Bug 22980 – 16 bit alignment for function arguments in 32 bit code

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2022-04-03T21:29:52Z
Last change time
2024-12-13T19:21:58Z
Assigned to
No Owner
Creator
Walter Bright
Moved to GitHub: dmd#20080 →

Comments

Comment #0 by bugzilla — 2022-04-03T21:29:52Z
void main() { test(); } align (16) struct Cent { ulong lo, hi; } public struct Int128 { Cent data; this(long hi, long lo) { data.hi = hi; data.lo = lo; } this(Cent data) { this.data = data; } Int128 foo(int a, Int128 op2, int b, Int128 op3) const // op2 and op3 are not 16 aligned when accessed { printf("&a: %p &op2: %p &b: %p &op3 %p\n", &a, &op2, &b, &op3); print(op2); return Int128(); } } import core.stdc.stdio; void print(Int128 c) { printf("%lld, %lld\n", c.data.hi, c.data.lo); } void print(Int128 c, Int128 d) { printf("%lld, %lld ", c.data.hi, c.data.lo); printf("%lld, %lld\n", d.data.hi, d.data.lo); } void test() { Int128 d = Int128(10, 20); Int128 c = Int128(5, 6); printf("&d = %p\n", &d); c.foo(1,d,2,c); // c and d are aligned to 16 when pushed on parameter stack bar(c, d); } Int128 bar(ref Int128 x, Int128 op2) { print(op2); return Int128(); } ------------------------------------------------------------- This will print garbage when compiled with -m32 on Linux. The trouble is the push of the arguments on the function call stack aligns the Int128 to 16 bytes, while foo() expects them to be not aligned. gcc does not align 16 byte objects on the function argument stack - it adds code to the function to copy the parameter to 16 byte aligned local storage.
Comment #1 by robert.schadek — 2024-12-13T19:21:58Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20080 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB