You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using align in structs, the .offsetof-property of fields is correct but real alignment is wrong:
$ ldc2 --version
LDC - the LLVM D compiler (0.12.0):
based on DMD v2.063.2 and LLVM 3.3
Default target: x86_64-redhat-linux-gnu
Host CPU: corei7
import std.stdio;
struct buggy {
align(1):
uint a;
ulong b;
}
void main() {
union uni {
ubyte[buggy.sizeof] raw;
buggy struc;
};
uni data;
// This is OK.
static assert(buggy.b.offsetof == uint.sizeof);
data.struc.b=0x0807060504030201;
writeln(buggy.b.offsetof);
// Print the real data layout, should be 4 zeros followed by 1,2..8
writeln(data.raw);
// This fails due to bad alignment of b as you can see above
assert(cast(ubyte)(data.struc.b) == data.raw[buggy.b.offsetof]);
}
The text was updated successfully, but these errors were encountered:
Confirmed on Git master. The issue is that we fail to mark the struct as packed on the LLVM IR level. As a workaround, you can use align(1) struct buggy { … } for the time being.
When using align in structs, the .offsetof-property of fields is correct but real alignment is wrong:
$ ldc2 --version
LDC - the LLVM D compiler (0.12.0):
based on DMD v2.063.2 and LLVM 3.3
Default target: x86_64-redhat-linux-gnu
Host CPU: corei7
The text was updated successfully, but these errors were encountered: