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

            Bug ID: 116190
           Summary: raised STORAGE_ERROR : stack overflow or erroneous
                    memory access with array of unbounded strings
           Product: gcc
           Version: 14.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
          Assignee: unassigned at gcc dot gnu.org
          Reporter: aj at ianozi dot com
                CC: dkm at gcc dot gnu.org
  Target Milestone: ---

Created attachment 58805
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58805&action=edit
Code that compiles but raises exception at runtime

I've tested this in both gnat 13 and 14 on Debian. I haven't tested it on mac
but I've heard it happens on MacOS too.

If I create an array of an unbounded string, and I try to initialize another
array using iteration with an advanced aggregate, it compiles fine but crashes
at runtime with:
raised STORAGE_ERROR : stack overflow or erroneous memory access
[bin/example]
0x42599a __gnat_error_handler at init.c:576
0x43a62e ??? at ???
0x407cfa Ada.Strings.Unbounded.Initialize at a-strunb.adb:1075
0x4021a7 example__Tthis_crashesT66bDI.0 at ???
0x40279c Example at example.adb:5
0x402cc6 Main at b__example.adb:248
0x4350b7 __libc_start_main at ???
0x402058 _start at ???

This is the line that crashes at runtime:
   This_Crashes : constant array (Natural range <>) of Unbounded_String :=
      [for I of My_Array => I];

I can dynamically create an array initialized by a range such as:
   This_Works : constant array (Natural range <>) of Unbounded_String :=
      [for I in My_Array'Range => My_Array(I)];

I can iterate over the array in the initialization if it's not an unbounded
string:
   This_Works_Too : constant array (Natural range <>) of Integer :=
      [for I of My_Array => Length (I)];


Same error if arrays are not constant or if it's using an array type instead of
just declaring the array.

I've attached the example.adb

Reply via email to