-
Notifications
You must be signed in to change notification settings - Fork 13.2k
[AArch64] Miscompilation of struct containing complex double and BitInt #89230
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
Comments
@llvm/issue-subscribers-backend-aarch64 Author: None (ostannard)
This code is miscompiled when targeting AArch64 at all optimisation levels:
extern void __aeabi_assert(const char *, const char *, int);
#define assert(e) ((e) ? (void)0 : __aeabi_assert(#e, __FILE__, __LINE__))
#include <complex.h>
union S131 {
double _Complex M0 __attribute__((aligned(16)));
signed _BitInt(124) M1;
};
void F94(union S131 P3) {
assert(P3.M0 == 1.0 + 2.0 * _Complex_I);
}
int main() {
union S131 P3 = {1.0 + 2.0 * _Complex_I};
F94(P3);
return 0;
} I think that the IR generated by clang is wrong, before any optimisations:
This is using |
This seems reproducible on x86 clang as well, so I don't think its a backend issue: https://godbolt.org/z/8c8deKPzq. |
There's no such thing as an allocation of 124 bits. An alloca's size is always a number in bytes, that size is always a multiple of the type's alignment, and it's legal to read and write the padding. So the allocation is 128 bits, i.e. 16 bytes, and the memcpy is fine. (It's possible there's some optimization in LLVM that doesn't handle this construct correctly, but that would be a separate issue. See also #64081.) |
Note, after #91364 it is allocating i128 https://godbolt.org/z/zfxvPEf3o . |
This code is miscompiled when targeting AArch64 at all optimisation levels:
I think that the IR generated by clang is wrong, before any optimisations:
This is using
%union.S131
, which is a 124-bit type, to store the value ofP3
, but it needs 128 bits of storage to hold thedouble _Complex
value. Thememcpy
in main copies 16 bytes into an allocation which is only 15 bytes.The text was updated successfully, but these errors were encountered: