Ver Fonte

* keep type when removing "1*", resolves #38840

florian há 3 anos atrás
pai
commit
08050086b9
2 ficheiros alterados com 24 adições e 2 exclusões
  1. 8 2
      compiler/nadd.pas
  2. 16 0
      tests/webtbs/tw38840.pp

+ 8 - 2
compiler/nadd.pas

@@ -827,7 +827,10 @@ implementation
               end
 
             else if (tordconstnode(right).value = 1) and (nodetype=muln) then
-              result := left.getcopy
+              { insert type conversion in case it is a 32*32 to 64 bit multiplication optimization,
+                the type conversion does not hurt because it is normally removed later on
+              }
+              result := ctypeconvnode.create_internal(left.getcopy,resultdef)
 
             else if (tordconstnode(right).value = -1) and (nodetype=muln) then
               result := ctypeconvnode.create_internal(cunaryminusnode.create(left.getcopy),left.resultdef)
@@ -895,7 +898,10 @@ implementation
               end
 
             else if (tordconstnode(left).value = 1) and (nodetype=muln) then
-              result := right.getcopy
+              { insert type conversion in case it is a 32*32 to 64 bit multiplication optimization,
+                the type conversion does not hurt because it is normally removed later on
+              }
+              result :=  ctypeconvnode.create_internal(right.getcopy,resultdef)
 
             else if (tordconstnode(left).value = -1) and (nodetype=muln) then
               result := ctypeconvnode.create_internal(cunaryminusnode.create(right.getcopy),right.resultdef)

+ 16 - 0
tests/webtbs/tw38840.pp

@@ -0,0 +1,16 @@
+{ %opt=-O4 -CriotR }
+
+{$mode objfpc}
+
+function f : integer;
+  begin
+    result:=1234;
+  end;
+
+var r, s, t, tablecols : integer;
+    
+begin
+  s := 1;
+  t := r + (s*tablecols);
+  t := r + (s*tablecols);
+end.