[COMMITTED] ada: Fix source location for crashes in expanded Loop_Entry attributes

Message ID 20230522085139.1727399-1-poulhies@adacore.com
State Accepted
Headers
Series [COMMITTED] ada: Fix source location for crashes in expanded Loop_Entry attributes |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Marc Poulhiès May 22, 2023, 8:51 a.m. UTC
  From: Piotr Trojanek <trojanek@adacore.com>

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.

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

---
 gcc/ada/exp_attr.adb | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
  

Patch

diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
index 7e71422eba3..a5791adf7dd 100644
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -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