Bladeren bron

* fix try_make_mul32to64() if it's called with a constant node on the
left (mantis #37878)
o can happen if use_generic_mul32to64 returns false

git-svn-id: trunk@47142 -

Jonas Maebe 4 jaren geleden
bovenliggende
commit
099134b545
3 gewijzigde bestanden met toevoegingen van 13 en 5 verwijderingen
  1. 1 0
      .gitattributes
  2. 4 5
      compiler/nadd.pas
  3. 8 0
      tests/webtbs/tw37878.pp

+ 1 - 0
.gitattributes

@@ -18493,6 +18493,7 @@ tests/webtbs/tw37806.pp svneol=native#text/pascal
 tests/webtbs/tw3782.pp svneol=native#text/plain
 tests/webtbs/tw37823.pp svneol=native#text/pascal
 tests/webtbs/tw37844.pp svneol=native#text/pascal
+tests/webtbs/tw37878.pp svneol=native#text/plain
 tests/webtbs/tw37926.pp svneol=native#text/pascal
 tests/webtbs/tw3796.pp svneol=native#text/plain
 tests/webtbs/tw3805.pp svneol=native#text/plain

+ 4 - 5
compiler/nadd.pas

@@ -3572,6 +3572,9 @@ implementation
         canbesignedconst, canbeunsignedconst: boolean;
       begin
         result := false;
+        { make sure that if there is a constant, that it's on the right }
+        if left.nodetype = ordconstn then
+          swapleftright;
         if is_32to64typeconv(left) then
           begin
             leftoriginallysigned:=is_signed(ttypeconvnode(left).left.resultdef);
@@ -3747,11 +3750,7 @@ implementation
 
         { make sure that if there is a constant, that it's on the right }
         if left.nodetype = ordconstn then
-          begin
-            temp := right;
-            right := left;
-            left := temp;
-          end;
+          swapleftright;
 
         { can we use a shift instead of a mul? }
         if not (cs_check_overflow in current_settings.localswitches) and

+ 8 - 0
tests/webtbs/tw37878.pp

@@ -0,0 +1,8 @@
+{$mode objfpc}
+ var i64: int64; w: word;
+begin
+{$Q+}
+w := 4096;
+i64 := 8191;
+i64 := i64 - 2*int64(w);
+end.