diff mbox series

[Ada] Enable current value propagation within pragma expressions

Message ID 20220517082727.GA1087192@adacore.com
State New
Headers show
Series [Ada] Enable current value propagation within pragma expressions | expand

Commit Message

Pierre-Marie de Rodat May 17, 2022, 8:27 a.m. UTC
This patch fixes an odd incomplete optimization within pragma
expressions. For example, in this code:

   X := True;
   pragma Assert (X = True);
   pragma Assert (X);

the first assertion was eliminated by the frontend (regardless of the
optimization switches), while the second assertion was only eliminated
by the backend and only with switch -O1 or similar.

The problem was that the current value propagation was disabled for
references immediately within pragma argument associations. This was
meant to avoid a crash when such a reference appears in pragma
Inspection_Point, but this wasn't a proper fix. The proper solution is
rather to not expand references in pragma Inspection_Point at all.

Actually, this expansion was enabled to avoid a yet another crash, when
the parameter of pragma Inspection_Point is a prival (i.e. a renaming of
private protected component). It turns out that none of these suspicious
problematic fixes is no longer necessary.

Cleanup related to fixes of current value propagation in expansion of
attribute Loop_Entry.

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

gcc/ada/

	* exp_ch2.adb (Expand_Current_Value): Remove special case for
	references immediately within pragma argument associations.
	* exp_prag.adb (Expand_Pragma_Inspection_Point): Remove special
	case for privals.
diff mbox series

Patch

diff --git a/gcc/ada/exp_ch2.adb b/gcc/ada/exp_ch2.adb
--- a/gcc/ada/exp_ch2.adb
+++ b/gcc/ada/exp_ch2.adb
@@ -150,13 +150,6 @@  package body Exp_Ch2 is
 
          and then OK_To_Do_Constant_Replacement (E)
 
-         --  Do not replace occurrences in pragmas (where names typically
-         --  appear not as values, but as simply names. If there are cases
-         --  where values are required, it is only a very minor efficiency
-         --  issue that they do not get replaced when they could be).
-
-         and then Nkind (Parent (N)) /= N_Pragma_Argument_Association
-
          --  Do not replace the prefixes of attribute references, since this
          --  causes trouble with cases like 4'Size. Also for Name_Asm_Input and
          --  Name_Asm_Output, don't do replacement anywhere, since we can have


diff --git a/gcc/ada/exp_prag.adb b/gcc/ada/exp_prag.adb
--- a/gcc/ada/exp_prag.adb
+++ b/gcc/ada/exp_prag.adb
@@ -34,7 +34,6 @@  with Elists;         use Elists;
 with Errout;         use Errout;
 with Exp_Ch11;       use Exp_Ch11;
 with Exp_Util;       use Exp_Util;
-with Expander;       use Expander;
 with Inline;         use Inline;
 with Lib;            use Lib;
 with Namet;          use Namet;
@@ -2390,10 +2389,7 @@  package body Exp_Prag is
          Set_Pragma_Argument_Associations (N, A);
       end if;
 
-      --  Process the arguments of the pragma and expand them. Expanding an
-      --  entity reference is a noop, except in a protected operation, where
-      --  a reference may have to be transformed into a reference to the
-      --  corresponding prival. Are there other pragmas that require this ???
+      --  Process the arguments of the pragma
 
       Rip := False;
       Assoc := First (Pragma_Argument_Associations (N));
@@ -2402,8 +2398,6 @@  package body Exp_Prag is
 
          Set_Address_Taken (Entity (Expression (Assoc)));
 
-         Expand (Expression (Assoc));
-
          --  If any of the objects have a freeze node, it must appear before
          --  pragma Inspection_Point, otherwise the entity won't be elaborated
          --  when Gigi processes the pragma.