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

            Bug ID: 120440
           Summary: [15/16 regression] gnat exception handling miscompiled
                    (`gnat ls` crashes when bootstrapped with
                    -march=znver3)
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: ada
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sjames at gcc dot gnu.org
                CC: dkm at gcc dot gnu.org
  Target Milestone: ---

Originally reported downstream in Gentoo at https://bugs.gentoo.org/956623.

```
$ ~/git/gcc/configure --prefix=/tmp/gcc-pfx --enable-languages=c,c++,ada
CFLAGS="-O2 -march=znver3" CXXFLAGS="-O2 -march=znver3" BOOT_CFLAGS="-O2
-march=znver3" BOOT_CXXFLAGS="-O2 -march=znver3"
$ make -j$(nproc) -l$(nproc) -Oline
$ make install
$  /tmp/gcc-pfx/bin/gnat ls

raised STORAGE_ERROR : stack overflow or erroneous memory access

```

```
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7cbb111 in free () from /usr/lib64/libc.so.6
(gdb) bt
#0  0x00007ffff7cbb111 in free () from /usr/lib64/libc.so.6
#1  0x00000000004f0909 in <__gnat_free> (ptr=<optimized out>) at
s-memory.adb:120
#2  0x000000000040f242 in
ada.exceptions.exception_propagation.gnat_gcc_exception_cleanup
(reason=<optimized out>, excep=<optimized out>) at ../rts/a-exexpr.adb:354
#3  0x000000000040f32f in <__gnat_end_handler_v1>
(gcc_exception=gcc_exception@entry=0x6fb610,
    saved_cleanup=saved_cleanup@entry=0x40f230
<ada.exceptions.exception_propagation.gnat_gcc_exception_cleanup>,
propagating_exception=propagating_exception@entry=0x0)
    at ../rts/a-exexpr.adb:519
#4  0x0000000000404f74 in gnatcmd () at
/home/sam/git/gcc/gcc/ada/gnatcmd.adb:378``
```

Valgrind shows this when it's miscompiled (it's silent on a good build) though
it does complete:
```
$ valgrind -q /tmp/gcc-pfx/bin/gnat ls
==22084== Invalid read of size 8
==22084==    at 0x40F239:
ada.exceptions.exception_propagation.gnat_gcc_exception_cleanup
(a-exexpr.adb:354)
==22084==    by 0x40F32E: <__gnat_end_handler_v1> (a-exexpr.adb:519)
==22084==    by 0x404F73: <gnatcmd.cold> (gnatcmd.adb:378)
==22084==    by 0x40A1D5: main (b~gnatcmd.adb:287)
==22084==  Address 0x4be82b8 is 8 bytes before a block of size 704 alloc'd
==22084==    at 0x48498D8: malloc (vg_replace_malloc.c:446)
==22084==    by 0x4F08AE: <__gnat_malloc> (s-memory.adb:79)
==22084==    by 0x502ADD: system.exceptions.machine.new_occurrence
(s-excmac.adb:36)
==22084==    by 0x40F21A:
ada.exceptions.exception_propagation.allocate_occurrence (a-exexpr.adb:329)
==22084==    by 0x40FEDC: <__gnat_raise_exception> (a-except.adb:1169)
==22084==    by 0x4F9DD0: system.val_util.bad_value (s-valuti.adb:61)
==22084==    by 0x4F975E: system.val_enum_8.impl.value_enumeration
(s-valuen.adb:154)
==22084==    by 0x428E86: gnatcmd (gnatcmd.adb:375)
==22084==    by 0x40A1D5: main (b~gnatcmd.adb:287)
==22084==
Usage: gnatls  switches  [list of object files]
[...]
```

```
$ /tmp/gcc-pfx/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/tmp/gcc-pfx/bin/gcc
COLLECT_LTO_WRAPPER=/tmp/gcc-pfx/libexec/gcc/x86_64-pc-linux-gnu/16.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /home/sam/git/gcc/configure --prefix=/tmp/gcc-pfx
--enable-languages=c,c++,ada CFLAGS='-O2 -march=znver3' CXXFLAGS='-O2
-march=znver3' 'BOOT_CFLAGS=-O2 -march=znver3' 'BOOT_CXXFLAGS=-O2
-march=znver3'
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.0.0 20250526 (experimental) (GCC)
```

Reply via email to