]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix source location for crashes in expanded Loop_Entry attributes
authorPiotr Trojanek <trojanek@adacore.com>
Fri, 10 Feb 2023 15:28:41 +0000 (16:28 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Mon, 22 May 2023 08:46:12 +0000 (10:46 +0200)
Historically, Loop_Entry attributes were expanded while expanding their
corresponding loops, so it was easier to use location of these loops for
expanded code. Now, these attributes are expanded where they appear, so
we can easily use the location of the attribute reference for expanded
code.

This matters when there is a crash in the expanded code, e.g. because of
a stack overflow in the declaration of an constant object that captures
the Loop_Entry prefix. Now backtrace will point to the source location
of the attribute, which is more helpful than the location of the loop.

gcc/ada/

* exp_attr.adb (Expand_Loop_Entry_Attribute): Use location of the
attribute reference, not of the loop statement.

gcc/ada/exp_attr.adb

index 7e71422eba3bc90a0d07b3906134b1055b42a289..a5791adf7dd748631366426a60a33cf421897f36 100644 (file)
@@ -1354,14 +1354,14 @@ package body Exp_Attr is
 
       --  Local variables
 
-      Pref      : constant Node_Id   := Prefix (N);
-      Base_Typ  : constant Entity_Id := Base_Type (Etype (Pref));
-      Exprs     : constant List_Id   := Expressions (N);
+      Pref      : constant Node_Id    := Prefix (N);
+      Base_Typ  : constant Entity_Id  := Base_Type (Etype (Pref));
+      Exprs     : constant List_Id    := Expressions (N);
+      Loc       : constant Source_Ptr := Sloc (N);
       Aux_Decl  : Node_Id;
       Blk       : Node_Id := Empty;
       Decls     : List_Id;
       Installed : Boolean;
-      Loc       : Source_Ptr;
       Loop_Id   : Entity_Id;
       Loop_Stmt : Node_Id;
       Result    : Node_Id := Empty;
@@ -1402,8 +1402,6 @@ package body Exp_Attr is
          Loop_Id := Entity (Identifier (Loop_Stmt));
       end if;
 
-      Loc := Sloc (Loop_Stmt);
-
       --  Step 2: Transform the loop
 
       --  The loop has already been transformed during the expansion of a prior