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

            Bug ID: 114398
           Summary: Unexpected storage error when "executing" return
                    statement.
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
          Assignee: unassigned at gcc dot gnu.org
          Reporter: d.van.raaij at gmail dot com
                CC: dkm at gcc dot gnu.org
  Target Milestone: ---

Created attachment 57741
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57741&action=edit
Reproducer

The program included in this report generates an unexpected storage error
(SIGSEGV) when the return statement on line 37 is being "executed". The issue
seems to be a regression in GCC 14.0.1 (20240228). 

A quick analysis using rr hints at an invalid value of "_init" in the expanded
code:

(rr) list
244           procedure reproducer__pkg__intIP (_init : out
245             reproducer__pkg__int; P60b : natural := 0; _init_level :
246             natural := 0) is
247           begin
248              if P60b = 0 then
249                 _init._tag := pkg__intP;     <<<<< Error occurs here.
250              end if;
251              if P60b /= 3 then
252                 $ada__finalization__limited_controlledIP (_init._parent,
253                   1);
(rr) p/x _init
$1 = <error reading variable: Cannot access memory at address 0x17fffffff>

The invalid memory address seems to come from a hidden argument of the "+"
operator function named "OaddBIPaccess":

(rr) frame
#0  reproducer.pkg."+" (left=..., right=..., <OaddBIPalloc>=0,
<OaddBIPstoragepool>=0x0, <OaddBIPfinalizationmaster>=0x7fffc9c35df0,
<OaddBIPtaskmaster>=-909943160, <OaddBIPactivationchain>=0x7f1d6258d340
<ada.strings.pattern_error>,
    <OaddBIPaccess>=0x17fffffff) at
/home/dvraaij/gnat14_bip_issue/reproducer.adb.dg:385
385           function reproducer__pkg__Oadd (left : reproducer__pkg__int;


*** Compilation ***

$ gnatmake -f reproducer.adb -cargs -O0 -g -gnatDGL -bargs -Es
gcc -c -O0 -g -gnatDGL reproducer.adb
gnatbind -Es -x reproducer.ali
gnatlink reproducer.ali

*** Program output ***

$ ./reproducer

raised STORAGE_ERROR : stack overflow or erroneous memory access
[/lib64/libgnat-14.so]
0x7f441f1d805f
[/lib64/libc.so.6]
0x7f441ecaf70e
[./reproducer]
0x404b95 reproducer__pkg__intIP.12 at reproducer.adb.dg:249
0x4047eb reproducer__pkg__Oadd.5 at reproducer.adb.dg:579
0x404df9 reproducer__test.15 at reproducer.adb.dg:733
0x404478 _ada_reproducer at reproducer.adb.dg:855
0x403bf7 Main at b~reproducer.adb:254
[/lib64/libc.so.6]
0x7f441ec99086
0x7f441ec99149
[./reproducer]
0x403633 _start at ???
0xfffffffffffffffe

raised PROGRAM_ERROR : reproducer.adb.dg:571 finalize/adjust raised exception
[./reproducer]
0x404af0 reproducer__pkg__Oadd__R80b___finalizer.8 at reproducer.adb.dg:571
0x404894 reproducer__pkg__Oadd.5 at reproducer.adb.dg:600
0x404df9 reproducer__test.15 at reproducer.adb.dg:733
0x404478 _ada_reproducer at reproducer.adb.dg:855
0x403bf7 Main at b~reproducer.adb:254
[/lib64/libc.so.6]
0x7f441ec99086
0x7f441ec99149
[./reproducer]
0x403633 _start at ???
0xfffffffffffffffe

*** Compiler version ***

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/14/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,m2,lto --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --enable-libstdcxx-backtrace
--with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu
--enable-plugin --enable-initfini-array
--with-isl=/builddir/build/BUILD/gcc-14.0.1-20240228/obj-x86_64-redhat-linux/isl-install
--enable-offload-targets=nvptx-none,amdgcn-amdhsa --enable-offload-defaulted
--without-cuda-driver --enable-gnu-indirect-function --enable-cet
--with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
--with-build-config=bootstrap-lto --enable-link-serialization=1
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.0.1 20240228 (Red Hat 14.0.1-0) (GCC)

Reply via email to