Created attachment 53484 [details] Minimal reproducer Building `program.ada` with optimisation -O2 or above: % gnatmake -O2 -flto main.adb Causes linker warning: ``` gcc -c -O2 -flto main.adb gcc -c -O2 -flto test.adb gnatbind -x main.ali gnatlink main.ali -O2 -flto test.adb: In function 'test__assign': test.adb:6:21: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=] 6 | The_Array (1) := AAAAA_Enum; | ^ test.ads:11:4: note: at offset -9223372036854775808 into destination object 'F' of size 4 11 | The_Array : T_Array; | ^ ``` The program is essentially: type First_Enum is (AAAAA_Enum); subtype Second_Enum is First_Enum; type T_Array is array (Integer range -1 .. 2) of Second_Enum; -- Change 'First to something >= 0 and the warning disappears. -- Using the First_Enum instead of Second_Enum and the warning disappears. GNATMAKE 12.1.0 - cause warning GNATMAKE 11.2.0 - cause warning GNATMAKE 10.3.0 - cause no warning
I suspect the diagnostic code does not handle negative lower bounds arrays correctly.
> I suspect the diagnostic code does not handle negative lower bounds arrays > correctly. Yes, see https://gcc.gnu.org/pipermail/gcc-patches/2022-August/599820.html
The master branch has been updated by Eric Botcazou <ebotcazou@gcc.gnu.org>: https://gcc.gnu.org/g:853ce8eea4ff97850a987167e603387b3d0f1401 commit r13-3084-g853ce8eea4ff97850a987167e603387b3d0f1401 Author: Eric Botcazou <ebotcazou@adacore.com> Date: Wed Oct 5 12:21:03 2022 +0200 Fix bogus -Wstringop-overflow warning in Ada It comes from a discrepancy between get_offset_range, which uses a signed type, and handle_array_ref, which uses an unsigned one, to do computations. gcc/ PR tree-optimization/106698 * pointer-query.cc (handle_array_ref): Fix handling of low bound. gcc/testsuite/ * gnat.dg/lto26.adb: New test. * gnat.dg/lto26_pkg1.ads, gnat.dg/lto26_pkg1.adb: New helper. * gnat.dg/lto26_pkg2.ads, gnat.dg/lto26_pkg2.adb: Likewise.
Fixed on the mainline.