-
-
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 alignment on memory loads with non-default alignment #4236
Labels
Comments
I don't plan on relying on this :) I think I'll just use void* and mark the functions as |
This issue is probably pervasive throughout LDC. align(1) float float1;
extern(C) auto fooglobalglobal() {
return float1; // also does not create IR with align(1)
} For the struct field, the frontend struct S {
byte i;
align(1) long data;
}
void foo( S* d) {
pragma(msg, d.data.alignof); // prints 8UL
} |
Example lit test: // RUN: %ldc -output-ll -of=%t.ll %s && FileCheck %s < %t.ll
struct S {
byte i;
align(1) long data;
}
// CHECK-LABEL: define{{.*}} @foofoofoo
extern(C) long foofoofoo(S *d) {
// CHECK: load i64, {{i64\*|ptr}} %2, align 1
return d.data;
// CHECK-LABEL: ret i64
}
align(1) float float1;
// CHECK-LABEL: define{{.*}} @fooglobalglobal
extern(C) auto fooglobalglobal() {
// CHECK: load float, {{float\*|ptr}} @_D18align_loads_gh42366float1f, align 1
return float1;
// CHECK-LABEL: ret float
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was very surprised to find this bug, so I hope I am wrong.
Testcase (https://d.godbolt.org/z/aYoM9odTo):
Is compiled to:
Note the
align 8
on loadingd.data
, whereas it should bealign 1
. This works on x86 but may break on CPU architecturers where some instructrions do not support unaligned loads.The text was updated successfully, but these errors were encountered: