https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121134

            Bug ID: 121134
           Summary: incorrectly specified array aggregate in protected
                    object causes bug box in GNAT 12.2.0
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
          Assignee: unassigned at gcc dot gnu.org
          Reporter: babiak at disroot dot org
                CC: dkm at gcc dot gnu.org
  Target Milestone: ---

Created attachment 61890
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61890&action=edit
a minimal example demonstrating the bug.

If, when inside a protected object, an array (length>1) is initialised using an
incomplete (n<length) positional array aggregate using the new square bracket
syntax, then GNAT will trigger a bug box.
This appears on my Linux (Devuan) x86_64 machine using gnatmake with gnat
version 12.2.0, but the compiler explorer at https://godbolt.org/z/nqEqj1Tcc
demonstrates the same bug box on all versions from 12.1.0 to 16.0.0 20250716.

The output of gnatmake, complete with bug box is below:

$ gnatmake bug -gnat2022 -save-temps
x86_64-linux-gnu-gcc-12 -c -gnat2022 -save-temps bug.adb
+===========================GNAT BUG DETECTED==============================+
| 12.2.0 (x86_64-linux-gnu) Storage_Error stack overflow or erroneous memory
access|
| Error detected at bug.adb:7:5                                            |
| Compiling bug.adb                                                        |
| Please submit a bug report; see https://gcc.gnu.org/bugs/ .              |
| Use a subject line meaningful to you and us to track the bug.            |
| Include the entire contents of this bug box in the report.               |
| Include the exact command that you entered.                              |
| Also include sources listed below.                                       |
+==========================================================================+

Please include these source files with error report
Note that list may not be accurate in some cases,
so please double check that the problem can still
be reproduced with the set of files listed.
Consider also -gnatd.n switch (see debug.adb).

bug.adb

bug.adb:9:31: warning: too few elements for type "my_array" defined at line 5
[enabled by default]
bug.adb:9:31: warning: expected 6 elements; found 0 elements [enabled by
default]
compilation abandoned
gnatmake: "bug.adb" compilation error

gcc -v produces the following output:
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian
12.2.0-14+deb12u1' --with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-12
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-vtable-verify --enable-plugin
--enable-default-pie --with-system-zlib --enable-libphobos-checking=release
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch
--disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/reproducible-path/gcc-12-12.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/reproducible-path/gcc-12-12.2.0/debian/tmp-gcn/usr
--enable-offload-defaulted --without-cuda-driver --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (Debian 12.2.0-14+deb12u1)


Adding -save-temps produces a bug.s with the following contents:
$ cat bug.s
        .file   "bug.adb"

The minimal example used for these outputs is attached. Elements may be added
to the array, but so long as there are less than there should be, the bug box
will appear. Too many elements will not. I first discovered this bug on arrays
of records, but I just realised today that the number of elements in the array
aggregate can be 0, and that means the syntax for non-record arrays would be
the same. And voila, an array of booleans also causes the bug box to appear.

Reply via email to