Comparisons of composite objects may be internally transformed by the
frontend into a special kind of node that facilitates their internal
management. If processing the comparison causes the internal declaration
of a subtype declaration associated with some sub-expression, the backend
may crash when generating the code.

After this patch the following test compiles fine.

package Q is
  type Rec (D : Positive) is record
    S : String (1 .. D);
  end record;

  type Field_T is (One);

  type Mask_T is array (Field_T) of Boolean;

  function F return Rec;
end Q;

with Q; use Q;
procedure P (A : Rec) is
  M : Mask_T;
  use type Rec;
begin
  M := (One => A /= F);
end;

Command: gcc -c p.adb

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-04-25  Javier Miranda  <mira...@adacore.com>

        * sem_util.adb (New_Copy_Tree.Visit_Entity): Extend previous change
        to generate new entities for subtype declarations located in
        Expression_With_Action nodes.

Index: sem_util.adb
===================================================================
--- sem_util.adb        (revision 247212)
+++ sem_util.adb        (working copy)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2016, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2017, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -17120,10 +17120,12 @@
          pragma Assert (not Is_Itype (Old_Entity));
          pragma Assert (Nkind (Old_Entity) in N_Entity);
 
-         --  Restrict entity creation to variable declarations. There is no
-         --  need to create variables declared in inner scopes.
+         --  Restrict entity creation to declarations of constants, variables
+         --  and subtypes. There is no need to duplicate entities declared in
+         --  inner scopes.
 
-         if not Ekind_In (Old_Entity, E_Constant, E_Variable)
+         if (not Ekind_In (Old_Entity, E_Constant, E_Variable)
+              and then Nkind (Parent (Old_Entity)) /= N_Subtype_Declaration)
            or else EWA_Inner_Scope_Level > 0
          then
             return;

Reply via email to