Procházet zdrojové kódy

* insert type casts when creating new unaryminus nodes during simplification, resolves #37508

git-svn-id: trunk@46309 -
florian před 5 roky
rodič
revize
d7ba09f543
3 změnil soubory, kde provedl 12 přidání a 5 odebrání
  1. 1 0
      .gitattributes
  2. 5 5
      compiler/nadd.pas
  3. 6 0
      tests/webtbs/tw37508.pp

+ 1 - 0
.gitattributes

@@ -18410,6 +18410,7 @@ tests/webtbs/tw37449.pp svneol=native#text/pascal
 tests/webtbs/tw37468.pp svneol=native#text/pascal
 tests/webtbs/tw37477.pp svneol=native#text/pascal
 tests/webtbs/tw37493.pp svneol=native#text/pascal
+tests/webtbs/tw37508.pp svneol=native#text/pascal
 tests/webtbs/tw3751.pp svneol=native#text/plain
 tests/webtbs/tw3758.pp svneol=native#text/plain
 tests/webtbs/tw3764.pp svneol=native#text/plain

+ 5 - 5
compiler/nadd.pas

@@ -737,7 +737,7 @@ implementation
               begin
                 case nodetype of
                   muln:
-                   result := cunaryminusnode.create(left.getcopy);
+                   result := ctypeconvnode.create_internal(cunaryminusnode.create(left.getcopy),left.resultdef);
                   else
                     ;
                 end;
@@ -818,9 +818,9 @@ implementation
               begin
                 case nodetype of
                   addn,orn,xorn:
-                   result := right.getcopy;
+                    result := right.getcopy;
                   subn:
-                   result := cunaryminusnode.create(right.getcopy);
+                    result := ctypeconvnode.create_internal(cunaryminusnode.create(right.getcopy),right.resultdef);
                   andn,muln:
                     begin
                       if (cs_opt_level4 in current_settings.optimizerswitches) or
@@ -844,7 +844,7 @@ implementation
               begin
                 case nodetype of
                   muln:
-                   result := cunaryminusnode.create(right.getcopy);
+                   result := ctypeconvnode.create_internal(cunaryminusnode.create(right.getcopy),right.resultdef);
                   else
                     ;
                 end;
@@ -976,7 +976,7 @@ implementation
                           end;
                       subn:
                         begin
-                          result:=cunaryminusnode.create(right.getcopy);
+                          result:=ctypeconvnode.create_internal(cunaryminusnode.create(right.getcopy),right.resultdef);
                           exit;
                         end;
                       else

+ 6 - 0
tests/webtbs/tw37508.pp

@@ -0,0 +1,6 @@
+{ %OPT=-O3 }
+var a, b : integer;
+begin
+  b := 0;
+  b := b - a - a { `b := b - a` won't trigger the error }
+end.