Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong alignment for struct fields on x86_64/amd64 #726

Closed
x539 opened this issue Sep 26, 2014 · 2 comments
Closed

Wrong alignment for struct fields on x86_64/amd64 #726

x539 opened this issue Sep 26, 2014 · 2 comments

Comments

@x539
Copy link

x539 commented Sep 26, 2014

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]);

}
@dnadlinger
Copy link
Member

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.

redstar pushed a commit that referenced this issue Sep 27, 2014
Fix typo in aa pointer rehash
dnadlinger added a commit that referenced this issue Oct 11, 2014
Fix Issue #726 — Wrong alignment for struct fields on x86_64/amd64
@dnadlinger
Copy link
Member

Fixed by #741.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants