Browse Source

* create muln with create instead of create_internal when converting "n - n mod const)" so pass1 works properly, resolves #40004

florian 2 years ago
parent
commit
247423400f
2 changed files with 13 additions and 4 deletions
  1. 5 4
      compiler/nadd.pas
  2. 8 0
      tests/webtbs/tw40004.pp

+ 5 - 4
compiler/nadd.pas

@@ -960,13 +960,14 @@ implementation
 
 
         { convert n - n mod const into n div const*const }
         { convert n - n mod const into n div const*const }
         if (nodetype=subn) and (right.nodetype=modn) and is_constintnode(tmoddivnode(right).right) and
         if (nodetype=subn) and (right.nodetype=modn) and is_constintnode(tmoddivnode(right).right) and
-          (left.isequal(tmoddivnode(right).left)) and not(might_have_sideeffects(left)) and
-	  not(cs_check_overflow in localswitches) then
+          (left.isequal(tmoddivnode(right).left)) and not(might_have_sideeffects(left)) { and
+	  not(cs_check_overflow in localswitches) } then
           begin
           begin
-            result:=caddnode.create_internal(muln,cmoddivnode.create(divn,left,tmoddivnode(right).right.getcopy),tmoddivnode(right).right);
+            result:=caddnode.create(muln,cmoddivnode.create(divn,left,tmoddivnode(right).right.getcopy),tmoddivnode(right).right);
             left:=nil;
             left:=nil;
             tmoddivnode(right).right:=nil;
             tmoddivnode(right).right:=nil;
-            result.localswitches:=localswitches;
+//            node_reset_flags(result,[nf_pass1_done]);
+//            do_firstpass(Result);
             exit;
             exit;
           end;
           end;
 
 

+ 8 - 0
tests/webtbs/tw40004.pp

@@ -0,0 +1,8 @@
+{$overflowchecks on}
+var
+	n: SizeUint;
+begin
+	n := 14 + random(0);
+	n := n - n mod 4;
+	writeln(n);
+end.