Explorar el Código

* fold also pointer additions/subtractions

git-svn-id: trunk@44199 -
florian hace 5 años
padre
commit
93521ae8e8
Se han modificado 1 ficheros con 12 adiciones y 10 borrados
  1. 12 10
      compiler/nadd.pas

+ 12 - 10
compiler/nadd.pas

@@ -701,7 +701,7 @@ implementation
           end;
 
         { Add,Sub,Mul,Or,Xor,Andn with constant 0, 1 or -1?  }
-        if is_constintnode(right) and is_integer(left.resultdef) then
+        if is_constintnode(right) and (is_integer(left.resultdef) or is_pointer(left.resultdef)) then
           begin
             if tordconstnode(right).value = 0 then
               begin
@@ -737,11 +737,11 @@ implementation
                 end;
               end
             { try to fold
-                          op
-                         /  \
-                       op  const1
-                      /  \
-                  const2 val
+                          op                         op
+                         /  \                       /  \
+                       op  const1       or        op  const1
+                      /  \                       /  \
+                  const2 val                   val const2
             }
             else if (left.nodetype=nodetype) and
               { there might be a mul operation e.g. longint*longint => int64 in this case
@@ -776,10 +776,12 @@ implementation
                       orn,
                       muln:
                         begin
-                          hp:=right;
-                          right:=taddnode(left).left;
-                          taddnode(left).left:=hp;
+                          { keep the order of val+const else pointer operations might cause an error }
+                          hp:=taddnode(left).left;
+                          taddnode(left).left:=right;
                           left:=left.simplify(false);
+                          right:=left;
+                          left:=hp;
                           result:=GetCopyAndTypeCheck;
                         end;
                       else
@@ -790,7 +792,7 @@ implementation
             if assigned(result) then
               exit;
           end;
-        if is_constintnode(left) and is_integer(right.resultdef) then
+        if is_constintnode(left) and (is_integer(right.resultdef) or is_pointer(right.resultdef)) then
           begin
             if tordconstnode(left).value = 0 then
               begin