https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106318
Bug ID: 106318 Summary: ICE when using 'Range in Ada22 Iterated Component Association Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ada Assignee: unassigned at gcc dot gnu.org Reporter: cthowie at netzero dot net Target Milestone: --- PLATFORM: GCC 12.1.0 toolchain on Windows 10 Intel x64 using MSYS2 (Mingw64). ISSUE: the use of 'Range sometimes causes an internal compiler error (ICE) when used in an Iterated Component Association per Ada 2022 syntax. Note that in the example program below that illustrates the bug, I had to use a nested subprogram, otherwise 'Range seemed to work OK in the Main subprogram itself: In short, this syntax works: new Local_Array'(for I in Arr'First .. Arr'Last => but this syntax crashes GNAT: new Local_Array'(for I in Arr'Range => It seems a temporary workaround for the bug is to replace use of 'Range with 'First .. 'Last in cases where GNAT crashes ('Range isn't universally broken). EXAMPLE PROGRAM DEMONSTRATING THE BUG ===================================== -- COMPILE WITH: gnatmake main.adb -gnat2022 -- The code as it stands triggers an ICE as indicated in the comment below. -- The culprit is the "for I in Arr'Range" being used in the Iterated -- Component Association syntax of Ada 2022. -- If you comment out the line that "FAILS!", and uncomment the line that "WORKS", -- then you'll get stable code using Arr'First .. Arr'Last. with Ada.Text_IO; use Ada.Text_IO; with Ada.Unchecked_Deallocation; procedure Main is type Int_Array is array (Positive range <>) of Integer; type Int_Array_Acc is access Int_Array; procedure Free is new Ada.Unchecked_Deallocation (Int_Array, Int_Array_Acc); Foo : constant Int_Array := [1, 2, 3]; procedure Nested -- replaces Arr with a similar one (Arr : in out Int_Array_Acc) is -- +===========================GNAT BUG ETECTED ============= -- | 12.1.0 (x86_64-w64-mingw32) GCC error: -- | in gnat_to_gnu_entity, at ada/gcc-interface/decl.cc:472 Replace : constant Int_Array_Acc := --new Int_Array'(for I in Arr'First .. Arr'Last => -- THIS WORKS new Int_Array'(for I in Arr'Range => -- THIS FAILS! (if Arr (I) = 2 then 0 else Arr (I))); begin Free (Arr); Arr := Replace; end Nested; Goo : Int_Array_Acc := new Int_Array'(Foo); begin Put_Line ("Goo =" & Goo.all'Image); -- should print [ 1, 2, 3] Nested (Goo); Put_Line ("Goo =" & Goo.all'Image); -- should print [ 1, 0, 3] Free (Goo); end Main;