From: Piotr Trojanek <troja...@adacore.com>

Fix crash occurring when overlay applies to protected component and expansion
is disabled, e.g. because of semantic checking mode (switch -gnatc) or because
the compiler is running in GNATprove mode.

Also, simply pick the type of overlaid object from the attribute prefix itself.

gcc/ada/ChangeLog:

        * sem_util.adb (Find_Overlaid_Entity): Don't call Etype on empty Ent;
        tune style; move computation of Overl_Typ out of the loop.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_util.adb | 30 ++++++------------------------
 1 file changed, 6 insertions(+), 24 deletions(-)

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 59bf060ee74..c74c10f2b5f 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -8935,9 +8935,9 @@ package body Sem_Util is
       --  In the second case, the expr is either Y'Address, or recursively a
       --  constant that eventually references Y'Address.
 
-      Ent := Empty;
+      Ent      := Empty;
       Ovrl_Typ := Empty;
-      Off := False;
+      Off      := False;
 
       Expr := Expression (N);
 
@@ -8967,6 +8967,8 @@ package body Sem_Util is
          end if;
       end loop;
 
+      Ovrl_Typ := Etype (Expr);
+
       --  This loop checks the form of the prefix for an entity, using
       --  recursion to deal with intermediate components.
 
@@ -8985,11 +8987,8 @@ package body Sem_Util is
                pragma Assert
                  (not Expander_Active
                   and then Is_Concurrent_Type (Scope (Ent)));
-               Ent := Empty;
-            end if;
-
-            if No (Ovrl_Typ) then
-               Ovrl_Typ := Etype (Ent);
+               Ent      := Empty;
+               Ovrl_Typ := Empty;
             end if;
 
             return;
@@ -8997,23 +8996,6 @@ package body Sem_Util is
          --  Check for components
 
          elsif Nkind (Expr) in N_Selected_Component | N_Indexed_Component then
-            if Nkind (Expr) = N_Selected_Component then
-               --  If Something.Other'Address, use
-               --  the Etype of the Other component.
-
-               if No (Ovrl_Typ) then
-                  Ovrl_Typ := Etype (Entity (Selector_Name (Expr)));
-               end if;
-
-            else
-               --  If Something(Index)'Address, use
-               --  the Etype of the array component.
-
-               if No (Ovrl_Typ) then
-                  Ovrl_Typ := Etype (Expr);
-               end if;
-            end if;
-
             Expr := Prefix (Expr);
             Off  := True;
 
-- 
2.43.0

Reply via email to