https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106297
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords|needs-reduction |
CC| |jakub at gcc dot gnu.org
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This boils down to:
struct S { long a, b, c; char d[0], e[0]; };
extern struct S s[1];
int
foo (int n)
{
int i;
for (i = 0; i < n; i++)
if ((__atomic_load_n (&s[i].c, 0) & s[i].b) == s[i].b)
break;
return i;
}
As the array has just a single element, this is UB if n > 1, but for some
reason we decide in the cunroll pass to completely unroll the loop. The first
iteration is full, the second one has the __atomic_load_8 call plus
__builtin_unreachable right after it.
Bet we only think that s[i_14].b for i_14 1 will be UB, while __atomic_load_8
(&s[i].c, 0) is fine. Even that is UB, even just forming the address, and even
if not - say the atomic would be on &s[i].a - it is accessing that member.
Though, for the atomic load we have
_8 = (sizetype) i_14;
_7 = _8 * 24;
_15 = _7 + 16;
_1 = &s + _15;
_2 = __atomic_load_8 (_1, 0);
in the IL while for the load everything in one stmt:
_4 = s[i_14].b;
The warning is on dead code here, the second __atomic_load_8 which would happen
only if is > 1.