Bug 113781 - internal error on naked iterated association in record aggregate
Summary: internal error on naked iterated association in record aggregate
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ada (show other bugs)
Version: 13.2.1
: P3 normal
Target Milestone: ---
Assignee: Eric Botcazou
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2024-02-06 09:09 UTC by Luke A. Guest
Modified: 2024-11-14 16:29 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-10-27 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Luke A. Guest 2024-02-06 09:09:54 UTC
procedure array_test is
   Size : constant := 4;

   type Vector is array (Natural range <>) of Integer;
   type Matrix is array (Natural range <>, Natural range <>) of Integer;
   type Combined (Which : Natural) is record
      case Which is
         when 0 =>
            V : Vector (1 .. Size * Size);

         when 1 =>
            M : Matrix (1 .. Size, 1 .. Size);

         when others =>
            null;
      end case;
   end record;

   V : constant Vector   := [for I in 1 .. Size => I];
   M : constant Combined := (Which => 0, V => for I in 1 .. Size * Size => I);
begin
   null;
end array_test;

ⓘ Building matrix_test=0.1.0-dev/matrix_test.gpr...                   
Compile
   [Ada]          array_test.adb
+===========================GNAT BUG DETECTED==============================+
| 13.2.1 20231014 (x86_64-pc-linux-gnu) Program_Error sem_util.adb:7351 explicit raise|
| Error detected at array_test.adb:20:51                                   |
| Compiling /home/laguest/src/mine-new/matrix_test/src/array_test.adb      |
| Please submit a bug report; see https://gcc.gnu.org/bugs/ .              |
| Use a subject line meaningful to you and us to track the bug.            |
| Include the entire contents of this bug box in the report.               |
| Include the exact command that you entered.                              |
| Also include sources listed below.                                       |
+==========================================================================+

Please include these source files with error report
Note that list may not be accurate in some cases,
so please double check that the problem can still
be reproduced with the set of files listed.
Consider also -gnatd.n switch (see debug.adb).

/home/laguest/src/mine-new/matrix_test/src/array_test.adb

compilation abandoned

   compilation of array_test.adb failed

gprbuild: *** compilation phase failed
error: Command ["gprbuild", "-s", "-j0", "-p", "-P", "/home/laguest/src/mine-new/matrix_test/matrix_test.gpr"] exited with code 4
error: Compilation failed.


Compiled with -O2, that is the only flag.
Comment 1 Eric Botcazou 2024-02-14 17:49:57 UTC
Optimization is irrelevant, it"s an issue in the front-end.
Comment 2 Eric Botcazou 2024-10-27 12:11:58 UTC
Still fails on the mainline.
Comment 3 Eric Botcazou 2024-10-27 12:33:14 UTC
The code is actually invalid since an iterated_component_association is not an expression, so an error is in order.  The correct syntax is:

   M : constant Combined := (Which => 0, V => (for I in 1 .. Size * Size => I));
Comment 4 Eric Botcazou 2024-10-27 12:44:09 UTC
For example:
p.adb:20:51: error: missing intermediate array aggregate
Comment 5 GCC Commits 2024-11-14 13:55:56 UTC
The master branch has been updated by Marc Poulhi?s <dkm@gcc.gnu.org>:

https://gcc.gnu.org/g:53133d07901afa45bd1cb3cdcf7f5d4ed2418dd7

commit r15-5241-g53133d07901afa45bd1cb3cdcf7f5d4ed2418dd7
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Mon Oct 28 11:19:10 2024 +0100

    ada: Fix internal error on misplaced iterated component association
    
    This happens for example in the others choice of a 1-dimensional array:
    
       A : array (1 .. Length) of Integer
             := (others => for Each in 1 .. Length => Each);
    
    or when it is used without parentheses for the array component of a record.
    
    gcc/ada/ChangeLog:
    
            PR ada/112524
            PR ada/113781
            * par-ch4.adb (P_Primary) <Tok_For>: Give an error about missing
            parentheses in the (purported) iterated component case too.
            (P_Unparen_Cond_Expr_Etc): Likewise.
            * sem.adb (Analyze): Raise PE on N_Iterated_Component_Association.
            * sem_util.ads (Diagnose_Iterated_Component_Association): Delete.
            * sem_util.adb (Diagnose_Iterated_Component_Association): Likewise.
Comment 6 Eric Botcazou 2024-11-14 16:29:45 UTC
Fixed on the mainline.