-
-
Notifications
You must be signed in to change notification settings - Fork 267
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 struct layout (alignment related), followup #4719 #4734
Comments
Godbolt: https://d.godbolt.org/z/o77Kafhr6 |
I guess this is an instance of #4236, due to Does this change things? struct KV {
align(4) S* s; // to prevent padding KV to 16 bytes on 64-bit targets
uint k;
} // note: still an overall alignment of 4 as before, and size of 8/12 bytes
struct Item {
KV v;
uint i;
} // now an alignment of 4, and same size 12/16 bytes
struct Table {
char a;
align(1) Item v; // pack tightly, no member/tail padding
} |
Oh sorry, just seen your // Also fails:
struct Item {
align(1):
KV v;
uint i;
} now, so aligning the members instead apparently isn't enough. |
This IR layout seems wrong: %example.Table = type { i8, %example.Item }
|
Weird, we only resort to the frontend type alignment (which would be 1, not matching the IR alignment) if the IR type isn't sized; we shouldn't be hitting this with the test case... Lines 215 to 224 in 6bd5d9a
|
It does indeed, fixing the |
I'm now very wary of the changes related to IR packedness; it has already shown two regressions (fortunately caught by asserts in the code). Struct layout changes in the past almost lead to severe data loss, only prevented with a lot of work. It spawned a whole struct introspection framework at Weka (the change was detectable by compile-time introspection). The issue now is worse because frontend introspection gives different values than IR, so Weka's introspection hashing of struct layout does not catch these bugs. |
There should at least be a simple brute-force fix, making the IR struct packed at the end if the D type alignment is less than the IR one, then we won't run into this, the D type alignment always being at least the IR one. With opaque pointers now, we shouldn't need to forward-declare aggregate types anymore though, so I'd prefer defining them at once (so that we'll never have to resort to the D type info), but that's probably much harder. |
This is a followup from #4719.
The layout of struct
Table
(orItem
) is wrong since LDC 1.31.In LLVM IR:
The text was updated successfully, but these errors were encountered: