[Ada] Use renamings in GNATprove mode for side-effects extraction

Message ID 20190710090318.GA80160@adacore.com
State New
Headers show
Series
  • [Ada] Use renamings in GNATprove mode for side-effects extraction
Related show

Commit Message

Pierre-Marie de Rodat July 10, 2019, 9:03 a.m.
In the GNATprove mode for formal verification, prefer renamings over
declaration of a constant to extract side-effects from expressions,
whenever the constant could be of an owning type, as declaring a
constant of an owning type has an effect on ownership which is
undesirable.

There is no impact on compilation.

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

2019-07-10  Yannick Moy  <moy@adacore.com>

gcc/ada/

	* exp_util.adb (Remove_Side_Effects): Prefer renamings for
	objects of possible owning type in GNATprove mode.

Patch

--- gcc/ada/exp_util.adb
+++ gcc/ada/exp_util.adb
@@ -11333,7 +11333,17 @@  package body Exp_Util is
          --  Generate:
          --    Rnn : Exp_Type renames Expr;
 
-         if Renaming_Req then
+         --  In GNATprove mode, we prefer to use renamings for intermediate
+         --  variables to definition of constants, due to the implicit move
+         --  operation that such a constant definition causes as part of the
+         --  support in GNATprove for ownership pointers. Hence we generate
+         --  a renaming for a reference to an object of a non-scalar type.
+
+         if Renaming_Req
+           or else (GNATprove_Mode
+                     and then Is_Object_Reference (Exp)
+                     and then not Is_Scalar_Type (Exp_Type))
+         then
             E :=
               Make_Object_Renaming_Declaration (Loc,
                 Defining_Identifier => Def_Id,