Browse Source

* avoid unncessary conversions of constants in 64 bit ints when doing constant folding

git-svn-id: trunk@45326 -
florian 5 years ago
parent
commit
ebcae70d72
1 changed files with 14 additions and 1 deletions
  1. 14 1
      compiler/nadd.pas

+ 14 - 1
compiler/nadd.pas

@@ -765,7 +765,13 @@ implementation
                           hp:=right;
                           right:=taddnode(left).right;
                           taddnode(left).right:=hp;
-                          left:=left.simplify(forinline);
+                          if resultdef.typ<>pointerdef then
+                            begin
+                              { ensure that the constant is not expanded to a larger type due to overflow,
+                                but this is only useful if no pointer operation is done }
+                              left:=ctypeconvnode.create_internal(left,resultdef);
+                              do_typecheckpass(left);
+                            end;
                           result:=GetCopyAndTypeCheck;
                         end;
                       else
@@ -785,6 +791,13 @@ implementation
                           hp:=taddnode(left).left;
                           taddnode(left).left:=right;
                           left:=left.simplify(forinline);
+                          if resultdef.typ<>pointerdef then
+                            begin
+                              { ensure that the constant is not expanded to a larger type due to overflow,
+                                but this is only useful if no pointer operation is done }
+                              left:=ctypeconvnode.create_internal(left,resultdef);
+                              do_typecheckpass(left);
+                            end;
                           right:=left;
                           left:=hp;
                           result:=GetCopyAndTypeCheck;