[Ada] Avoid spurious mismatch error of assertion policy in generics

Message ID 20191213095501.GA14019@adacore.com
State New
Headers show
Series
  • [Ada] Avoid spurious mismatch error of assertion policy in generics
Related show

Commit Message

Pierre-Marie de Rodat Dec. 13, 2019, 9:55 a.m.
Because of the way generics are analyzed, it is possible that an
assertion pragma is transformed into a Check pragma by the time ghost
code inside the assertion is checked for a possible mismatch of
assertion policy. In that case, the original pragma that led to the
Check pragma should be retrieved.

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

2019-12-13  Yannick Moy  <moy@adacore.com>

gcc/ada/

	* sem_util.adb (Original_Aspect_Pragma_Name): Go through
	Original_Node for pragma.

Patch

--- gcc/ada/sem_util.adb
+++ gcc/ada/sem_util.adb
@@ -23326,13 +23326,16 @@  package body Sem_Util is
          Item := Corresponding_Aspect (Item);
       end if;
 
-      --  Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
+      --  Retrieve the name of the aspect/pragma. As assertion pragmas from
+      --  a generic instantiation might have been rewritten into pragma Check,
+      --  we look at the original node for Item. Note also that Pre, Pre_Class,
       --  Post and Post_Class rewrite their pragma identifier to preserve the
-      --  original name.
+      --  original name, so we look at the original node for the identifier.
       --  ??? this is kludgey
 
       if Nkind (Item) = N_Pragma then
-         Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
+         Item_Nam :=
+           Chars (Original_Node (Pragma_Identifier (Original_Node (Item))));
 
       else
          pragma Assert (Nkind (Item) = N_Aspect_Specification);