https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123978
Bug ID: 123978
Summary: [16 Regression] leptonica miscompilation on aarch64
since r16-1398
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: jakub at gcc dot gnu.org
Target Milestone: ---
struct A { unsigned b, c, *d; };
[[gnu::noipa]] int
foo (struct A *a)
{
__builtin_memset (a->d, 0, ((long long) sizeof (unsigned)) * a->b * a->c);
return 0;
}
int
main ()
{
struct A a;
unsigned b[1024];
__builtin_memset (b, 0x55, sizeof (b));
a.b = 31;
a.c = 31;
a.d = b;
foo (&a);
for (int i = 0; i < 961; ++i)
if (b[i] != 0)
__builtin_abort ();
}
is miscompiled with -O2 starting with my
r16-1398-g8154fc95f097a146f9c80edcaafb2baff73065b5 ranger use during expansion
patch on aarch64-linux.
The memset call is somehow optimized away for some reason.
optimized dump has:
_1 = a_10(D)->d;
_2 = a_10(D)->b;
_4 = a_10(D)->c;
# RANGE [irange] long long int [0, +INF] MASK 0x7fffffffffffffff VALUE 0x0
_6 = _2 w* _4;
# RANGE [irange] long long int [0, 0][4, 9223372036854775804] MASK
0x7ffffffffffffffc VALUE 0x0
_7 = _6 * 4;
# RANGE [irange] long unsigned int [0, 0][4, 9223372036854775804] MASK
0x7ffffffffffffffc VALUE 0x0
_8 = (long unsigned int) _7;
__builtin_memset (_1, 0, _8);
return 0;