(Sorry if I included too much information, this is my first time making a manual bug report by email.)

I ran into this error when I forgot to specify all the elements in an array aggregate, but instead of a compiler error or warning, I got a bug box. To be specific: Inside a protected object, I have an array of records. Instead of specifying it with a full list of elements, I forgot to say "others =>" before the record aggregate I intended to use for all elements. That is, `variable: array_type:= [[record_element=>Value]];`. This triggered a bug box, saying the error was detected at the beginning of the protected object's spec.

The minimal example I came up with is attached.

The bug appears for both discriminated and non-discriminated records, but only if the variable definition is inside a protected object. Or at least, I haven't found any other ways to trigger it. The output of gnatmake, complete with bug box is below:

=== BEGIN ===
$ gnatmake bug -gnat2022
x86_64-linux-gnu-gcc-12 -c -gnat2022 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:11: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:13:35: warning: too few elements for type "struct_array" defined at line 9 [enabled by default] bug.adb:13:35: warning: expected 2 elements; found 1 element [enabled by default]
compilation abandoned
gnatmake: "bug.adb" compilation error
=== END ===

As can be seen, the exact command line passed to GCC was "x86_64-linux-gnu-gcc-12 -c -gnat2022 bug.adb". I have compiled this code with various other flags, and it persists (the gnat2022 flag is needed for the aggregate syntax I'm using).

I am running a Devuan linux machine (debian-based, without Systemd), with `uname -a` saying "Linux hostname 6.1.0-32-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.129-1 (2025-03-06) x86_64 GNU/Linux"

The output of `gcc -v` is below:

=== BEGIN ===
$ 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' --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/gcc-12-bTRWOB/gcc-12-12.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-bTRWOB/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)
=== END ===

I would expect to either have the "too few elements for type" warning to cause an error, or the compiler to compile normally and fail at runtime with a constraint_error: range check failed. Or maybe fail with some other error, such as about how the protected object doesn't have a body (it can have a body, it's just not needed for the bug to appear).
Instead, I get the bug box, as included above.

Sorry again if I included the wrong information, or formatted the email wrong or anything like that. It's my first time using a gnu mailing list.
-- compile with gnatmake -gnat2022
procedure bug is
    type index is range 1..6;

    type struct is record
        arg: Boolean:=True;
    end record;

    type struct_array is array(index) of struct;

    protected object is
    private
        variable: struct_array := [
            [arg=>False]
        ];
    end;
begin
    null;
end bug;

Reply via email to