diff mbox series

[Ada] Unnesting problems with expansion of Loop_Entry attribute

Message ID 20200603100304.GA6493@adacore.com
State New
Headers show
Series [Ada] Unnesting problems with expansion of Loop_Entry attribute | expand

Commit Message

Pierre-Marie de Rodat June 3, 2020, 10:03 a.m. UTC
For expansion of a Loop_Entry attribute, a function body is generated in
association with the condition of a generated while loop, and the
entities within the function need to have their scopes reset to the
function Entity_Id, for proper handling of up-level-reference processing
in the GNAT-LLVM compiler. The existing handling only did this for
itypes associated with the loop, but there can be other kinds of
entities that also need to be reset, so the condition of the loop was
relaxed to allow resetting for more entity cases. However, note that the
fix is likely still incomplete (potentially allowing either too many or
too few entity cases).

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

2020-06-03  Gary Dismukes  <dismukes@adacore.com>

gcc/ada/

	* exp_attr.adb (Expand_Loop_Entry_Attribute): Revise loop that
	resets the scopes of entities associated with Loop_Id to the
	scope of the new function, so the resetting is not restricted to
	itypes, but excludes loop parameters and the function entity
	itself. However, this fix is believed to be incomplete and a ???
	comment is added to indicate that.
diff mbox series

Patch

--- gcc/ada/exp_attr.adb
+++ gcc/ada/exp_attr.adb
@@ -1434,22 +1434,36 @@  package body Exp_Attr is
                Insert_Action (Loop_Stmt, Func_Decl);
                Pop_Scope;
 
-               --  The analysis of the condition may have generated itypes
-               --  that are now used within the function: Adjust their
-               --  scopes accordingly so that their use appears in their
-               --  scope of definition.
+               --  The analysis of the condition may have generated entities
+               --  (such as itypes) that are now used within the function.
+               --  Adjust their scopes accordingly so that their use appears
+               --  in their scope of definition.
 
                declare
-                  Ityp : Entity_Id;
+                  Ent : Entity_Id;
 
                begin
-                  Ityp := First_Entity (Loop_Id);
-
-                  while Present (Ityp) loop
-                     if Is_Itype (Ityp) then
-                        Set_Scope (Ityp, Func_Id);
+                  Ent := First_Entity (Loop_Id);
+
+                  while Present (Ent) loop
+                     --  Various entities that now occur within the function
+                     --  need to have their scope reset, but not all entities
+                     --  associated with Loop_Id are now inside the function.
+                     --  The function entity itself and loop parameters can
+                     --  be outside the function, and there may be others.
+                     --  It's not clear how the determination of what entity
+                     --  scopes need to be adjusted can be made accurately.
+                     --  Perhaps it will be necessary to traverse the function
+                     --  body to find the exact entities whose scopes need to
+                     --  be reset to the function's Entity_Id. ???
+
+                     if Ekind (Ent) /= E_Loop_Parameter
+                       and then Ent /= Func_Id
+                     then
+                        Set_Scope (Ent, Func_Id);
                      end if;
-                     Next_Entity (Ityp);
+
+                     Next_Entity (Ent);
                   end loop;
                end;