Parcourir la source

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

git-svn-id: trunk@45326 -
florian il y a 5 ans
Parent
commit
ebcae70d72
1 fichiers modifiés avec 14 ajouts et 1 suppressions
  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;