diff mbox series

[Ada] Spurious accessibility error on return aggregate in GNATprove mode

Message ID 20200525150426.GA102349@adacore.com
State New
Headers show
Series [Ada] Spurious accessibility error on return aggregate in GNATprove mode | expand

Commit Message

Pierre-Marie de Rodat May 25, 2020, 3:04 p.m. UTC
This patch fixes an issue whereby valid actuals within return aggregates
could trigger spurious accessibility errors in GNATprove mode.

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

2020-05-25  Justin Squirek  <squirek@adacore.com>

gcc/ada/

	* sem_ch6.adb (Check_Return_Obj_Accessibility): Use original
	node to avoid looking at expansion done in GNATprove mode.
diff mbox series

Patch

--- gcc/ada/sem_ch6.adb
+++ gcc/ada/sem_ch6.adb
@@ -798,44 +798,44 @@  package body Sem_Ch6 is
                                       N_Discriminant_Association)
                then
                   Expr := Expression (Assoc);
+               else
+                  Expr := Empty;
                end if;
 
                --  This anonymous access discriminant has an associated
                --  expression which needs checking.
 
-               if Nkind (Expr) = N_Attribute_Reference
+               if Present (Expr)
+                 and then Nkind (Expr) = N_Attribute_Reference
                  and then Attribute_Name (Expr) /= Name_Unrestricted_Access
                then
                   --  Obtain the object to perform static checks on by moving
                   --  up the prefixes in the expression taking into account
                   --  named access types.
 
-                  Obj := Prefix (Expr);
+                  Obj := Original_Node (Prefix (Expr));
                   while Nkind_In (Obj, N_Indexed_Component,
                                        N_Selected_Component)
                   loop
+                     Obj := Original_Node (Prefix (Obj));
+
                      --  When we encounter a named access type then we can
                      --  ignore accessibility checks on the dereference.
 
-                     if Ekind (Etype (Prefix (Obj)))
+                     if Ekind (Etype (Obj))
                           in E_Access_Type ..
                              E_Access_Protected_Subprogram_Type
                      then
-                        if Nkind (Obj) = N_Selected_Component then
-                           Obj := Selector_Name (Obj);
+                        if Nkind (Parent (Obj)) = N_Selected_Component then
+                           Obj := Selector_Name (Parent (Obj));
                         end if;
                         exit;
                      end if;
 
                      --  Skip over the explicit dereference
 
-                     if Nkind (Prefix (Obj)) = N_Explicit_Dereference then
-                        Obj := Prefix (Prefix (Obj));
-
-                     --  Otherwise move up to the next prefix
-
-                     else
-                        Obj := Prefix (Obj);
+                     if Nkind (Obj) = N_Explicit_Dereference then
+                        Obj := Original_Node (Prefix (Obj));
                      end if;
                   end loop;