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

Struct alignment is not correct #430

Closed
yazd opened this issue Jul 20, 2013 · 4 comments
Closed

Struct alignment is not correct #430

yazd opened this issue Jul 20, 2013 · 4 comments

Comments

@yazd
Copy link

yazd commented Jul 20, 2013

Using ldc-0.11 on Linux-64bit little endian system, the following code:

import std.stdio;

align(1) struct Foo {
align(1):
  ushort b;
  uint c;
}

void main() {
  ubyte[6] arr = [0x01, 0x01, 0x01, 0x00, 0x00, 0x01];
  Foo f = cast(Foo) arr;
  writeln(f); // prints Foo(257, 1841692928)
  writeln(f.sizeof); // prints 6 correctly
}

Using dmd2.063.2, the same code prints correctly Foo(257, 16777217) and 6

@redstar
Copy link
Member

redstar commented Aug 4, 2013

I can reproduce it. Thanks for the report.

@redstar
Copy link
Member

redstar commented Aug 4, 2013

From a first look at the IR, the struct Foo is translated to:

%ldc_github_430.Foo = type { i16, i32 }

but in this case it should be

%ldc_github_430.Foo = type <{ i16, i32 }>

because struct Foo is a packed structure.

@yazd
Copy link
Author

yazd commented Aug 5, 2013

Exactly. Thank you for looking into this.

redstar added a commit that referenced this issue Aug 5, 2013
redstar added a commit that referenced this issue Aug 5, 2013
@redstar
Copy link
Member

redstar commented Aug 5, 2013

The bug should be fixed with my latest commit. I also added a new test case.

@redstar redstar closed this as completed Aug 8, 2013
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