Browse Source

- reverted r46457, accidentally committed (breaks -Oooptcse)

git-svn-id: trunk@46459 -
Jonas Maebe 5 years ago
parent
commit
a88288bab3
3 changed files with 30 additions and 12 deletions
  1. 11 2
      compiler/nbas.pas
  2. 13 9
      compiler/ncgbas.pas
  3. 6 1
      compiler/nutils.pas

+ 11 - 2
compiler/nbas.pas

@@ -140,16 +140,25 @@ interface
            even if the creator didn't mind)
          }
          ti_addr_taken,
+         { temps can get an extra node tree that contains the value to which
+           they should be initialised when they are created. this initialisation
+           has to be performed right before the first reference to the temp.
+           this flag indicates that the ttempcreatenode has been
+           processed by pass_generate_code, but that the first ttemprefnode
+           hasn't yet and hence will have to perform the initialisation
+         }
+         ti_executeinitialisation,
          { in case an expression like "inc(x[func()],1)" is translated into
            a regular addition, you have to create a temp to hold the address
            representing x[func()], since otherwise func() will be called twice
            and that can spell trouble in case it has side effects. on platforms
-           without pointers, we cannot just take the address though. This flag will,
+           without pointers, we cannot just take the address though. this flag
+           has to be combined with ti_executeinitialisation above and will,
            rather than loading the value at the calculated location and store
            it in the temp, keep a copy of the calculated location if possible
            and required (not possible for regvars, because SSA may change their
            register, but not required for them either since calculating their
-           location has no side-effects)
+           location has no side-effects
          }
          ti_reference,
          { this temp only allows reading (makes it possible to safely use as

+ 13 - 9
compiler/ncgbas.pas

@@ -510,7 +510,20 @@ interface
           end;
         includetempflag(ti_valid);
         if assigned(tempinfo^.tempinitcode) then
+          includetempflag(ti_executeinitialisation);
+      end;
+
+
+{*****************************************************************************
+                             TTEMPREFNODE
+*****************************************************************************}
+
+    procedure tcgtemprefnode.pass_generate_code;
+      begin
+        if ti_executeinitialisation in tempflags then
           begin
+            { avoid recursion }
+            excludetempflag(ti_executeinitialisation);
             secondpass(tempinfo^.tempinitcode);
             if (ti_reference in tempflags) then
               begin
@@ -536,15 +549,6 @@ interface
                 hlcg.g_reference_loc(current_asmdata.CurrAsmList,tempinfo^.typedef,tempinfo^.tempinitcode.location,tempinfo^.location);
               end;
           end;
-      end;
-
-
-{*****************************************************************************
-                             TTEMPREFNODE
-*****************************************************************************}
-
-    procedure tcgtemprefnode.pass_generate_code;
-      begin
         { check if the temp is valid }
         if not(ti_valid in tempflags) then
           internalerror(200108231);

+ 6 - 1
compiler/nutils.pas

@@ -1442,7 +1442,12 @@ implementation
                (vo_volatile in tabstractvarsym(tloadnode(n).symtableentry).varoptions)
              )
             )
-           ) then
+           ) or
+           { foreachonode does not recurse into the init code for temprefnode as this is done for
+             by the tempcreatenode but the considered tree might not contain the tempcreatenode so play
+             save and recurce into the init code if there is any }
+           ((n.nodetype=temprefn) and (ti_executeinitialisation in ttemprefnode(n).tempflags) and
+            might_have_sideeffects(ttemprefnode(n).tempinfo^.tempinitcode,pmhs_flags(arg)^)) then
            result:=fen_norecurse_true
       end;