[Bug rtl-optimization/67676] New: Implicit alignment of struct not applied to members
olegendo at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Sep 22 02:06:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67676
Bug ID: 67676
Summary: Implicit alignment of struct not applied to members
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: olegendo at gcc dot gnu.org
Target Milestone: ---
Target: sh*-*-*
I've noticed this while doing PR 67675...
On strict-alignment targets (like SH) a pointer to a struct is always assumed
to be aligned:
struct S
{
int a, b, c;
char s[64];
};
'struct S*' will always be 4 byte aligned.
Accessing a member works as expected:
int foo4 (struct S* x)
{
return x->b;
}
mov.l @(4,r4),r0
rts/n
However, when the address of a member is passed to __builtin_strcmp, the
alignment is lost somehow:
int foo5 (struct S* x)
{
return __builtin_strcmp (x->s, "1234");
}
Here the builtin strcmp expander will see x->s with an alignment of 1, although
it's 4.
Adding an alignment hint gives the expected result:
int foo6 (struct S* x)
{
struct S* xx = (struct S*)__builtin_assume_aligned (x, 4);
return __builtin_strcmp (xx->s, "1234");
}
I'm not sure whether this is a tree or RTL problem. Happens for C and C++.
Possibly related: PR 23467, PR 50417
More information about the Gcc-bugs
mailing list