public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ada/106318] New: ICE when using 'Range in Ada22 Iterated Component Association
@ 2022-07-15 18:57 cthowie at netzero dot net
  2023-05-11 16:17 ` [Bug ada/106318] " ebotcazou at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: cthowie at netzero dot net @ 2022-07-15 18:57 UTC (permalink / raw)
  To: gcc-bugs

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;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug ada/106318] ICE when using 'Range in Ada22 Iterated Component Association
  2022-07-15 18:57 [Bug ada/106318] New: ICE when using 'Range in Ada22 Iterated Component Association cthowie at netzero dot net
@ 2023-05-11 16:17 ` ebotcazou at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2023-05-11 16:17 UTC (permalink / raw)
  To: gcc-bugs

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

Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |ebotcazou at gcc dot gnu.org
   Target Milestone|---                         |13.0
         Resolution|---                         |FIXED

--- Comment #2 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
Fixed in GCC 13.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-11 16:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-15 18:57 [Bug ada/106318] New: ICE when using 'Range in Ada22 Iterated Component Association cthowie at netzero dot net
2023-05-11 16:17 ` [Bug ada/106318] " ebotcazou at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).