-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[AArch64] LLVM generates unaligned access with -mstrict-align on AArch64 #95811
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
Caused by b062fff, I think. |
@llvm/issue-subscribers-backend-aarch64 Author: Vitaly Cheptsov (vit9696)
Consider the following command-line:
(1) Example 1 ("GodBolt":https://godbolt.org/z/35s8h7Kdz): <cut> <details> typedef struct
{
void* ccc[3];
void* mmm;
void* ddd;
unsigned eee[2];
_Bool bbb[8];
_Bool ggg;
_Bool abs;
unsigned char kkk[16];
} struct1;
typedef struct struct2
{
void* block[3];
unsigned char pass_flags[2];
unsigned int index[19];
struct1 yyy[];
} struct2;
union union1
{
unsigned u32;
struct
{
unsigned ggg : 24;
unsigned ffffffx : 2;
unsigned ffffffy : 2;
unsigned ffffffz : 2;
unsigned ffffffw : 2;
} aaa;
};
void func2(unsigned value);
unsigned func1(struct2* instr, unsigned yyy);
static void func3(struct1* yyy, union union1 zzzz)
{
func2(zzzz.u32);
if (yyy->ddd)
{
union union1 zzzz = {0};
func3(yyy->ddd, zzzz);
}
}
void bug(struct2* aaa);
void bug(struct2* aaa)
{
for (unsigned i = 0; i < 256; i++)
{
unsigned a = func1(aaa, i);
union union1 yyy;
yyy.aaa.ggg = aaa->yyy[i].ggg;
if (a <= 4)
{
yyy.aaa.ffffffx = aaa->yyy[i].kkk[0];
yyy.aaa.ffffffy = aaa->yyy[i].kkk[1];
yyy.aaa.ffffffz = aaa->yyy[i].kkk[2];
yyy.aaa.ffffffw = aaa->yyy[i].kkk[3];
}
func3(&aaa->yyy[i], yyy);
}
} </details> </cut> Output: <cut> <details>
</details> </cut> Note (2) Example 2 ("GodBolt":https://godbolt.org/z/nsovb6s1f): <cut> <details> void f(char p[restrict], char *q)
{
for (int i = 0; i < 4; i++)
p[i] = -q[i];
}
void g(char p[restrict], char *q)
{
for (int i = 0; i < 4; i++)
p[i] = q[i];
} </details> </cut> Output: <cut> <details> f: // @<!-- -->f
movi v0.2d, #<!-- -->0000000000000000
ldr s1, [x1]
usubw v0.8h, v0.8h, v1.8b
umov w8, v0.h[3]
umov w9, v0.h[2]
umov w10, v0.h[1]
umov w11, v0.h[0]
strb w8, [x0, #<!-- -->3]
strb w9, [x0, #<!-- -->2]
strb w10, [x0, #<!-- -->1]
strb w11, [x0]
ret
g: // @<!-- -->g
ldrb w8, [x1, #<!-- -->3]
ldrb w9, [x1, #<!-- -->2]
ldrb w10, [x1, #<!-- -->1]
ldrb w11, [x1]
strb w8, [x0, #<!-- -->3]
strb w9, [x0, #<!-- -->2]
strb w10, [x0, #<!-- -->1]
strb w11, [x0]
ret </details> Note Tested on 18.1.8. This results in unaligned access exception raised on targets with strict alignment enabled in hardware. |
Uh oh!
There was an error while loading. Please reload this page.
Consider the following command-line:
(1) Example 1 ("GodBolt":https://godbolt.org/z/35s8h7Kdz):
Output:
Note
ldur s0, [x8, #162]
.(2) Example 2 ("GodBolt":https://godbolt.org/z/nsovb6s1f):
Output:
Note
ldr s1, [x1]
Tested on 18.1.8.
This results in unaligned access exception raised on targets with strict alignment enabled in hardware.
The text was updated successfully, but these errors were encountered: