public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-501] [Ada] Fix expansion of attribute Loop_Entry wrt value propagation
@ 2022-05-16  8:45 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2022-05-16  8:45 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:7e0c853c6f6a2987ac7616cbfdd52bb41d598bd5

commit r13-501-g7e0c853c6f6a2987ac7616cbfdd52bb41d598bd5
Author: Piotr Trojanek <trojanek@adacore.com>
Date:   Wed Mar 16 13:36:40 2022 +0100

    [Ada] Fix expansion of attribute Loop_Entry wrt value propagation
    
    When expanding attribute Loop_Entry we create constant object
    declarations and put them just before the loop. The current values of
    variables at the point of Loop_Entry attribute must not be used when
    analysing the initialization expressions of these constants, because
    they might be different from the values at the loop entry itself.
    
    gcc/ada/
    
            * exp_attr.adb (Expand_Loop_Entry_Attribute): Disable value
            propagation when analysing the constant that holds the
            Loop_Entry prefix value.

Diff:
---
 gcc/ada/exp_attr.adb | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
index e6d3e74971f..daab82fe11a 100644
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -26,6 +26,7 @@
 with Aspects;        use Aspects;
 with Atree;          use Atree;
 with Checks;         use Checks;
+with Debug;          use Debug;
 with Einfo;          use Einfo;
 with Einfo.Entities; use Einfo.Entities;
 with Einfo.Utils;    use Einfo.Utils;
@@ -1792,23 +1793,30 @@ package body Exp_Attr is
          Push_Scope (Scope (Loop_Id));
       end if;
 
-      --  The analysis of the conditional block takes care of the constant
-      --  declaration.
+      --  Analyze constant declaration with simple value propagation disabled,
+      --  because the values at the loop entry might be different than the
+      --  values at the occurrence of Loop_Entry attribute.
 
-      if Present (Result) then
-         Rewrite (Loop_Stmt, Result);
-         Analyze (Loop_Stmt);
-
-      --  The conditional block was analyzed when a previous 'Loop_Entry was
-      --  expanded. There is no point in reanalyzing the block, simply analyze
-      --  the declaration of the constant.
+      declare
+         Save_Debug_Flag_MM : constant Boolean := Debug_Flag_MM;
+      begin
+         Debug_Flag_MM := True;
 
-      else
          if Present (Aux_Decl) then
             Analyze (Aux_Decl);
          end if;
 
          Analyze (Temp_Decl);
+
+         Debug_Flag_MM := Save_Debug_Flag_MM;
+      end;
+
+      --  If the conditional block has just been created, then analyze it;
+      --  otherwise it was analyzed when a previous 'Loop_Entry was expanded.
+
+      if Present (Result) then
+         Rewrite (Loop_Stmt, Result);
+         Analyze (Loop_Stmt);
       end if;
 
       Rewrite (N, New_Occurrence_Of (Temp_Id, Loc));


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-16  8:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-16  8:45 [gcc r13-501] [Ada] Fix expansion of attribute Loop_Entry wrt value propagation Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).