浏览代码

* add/sub nodes with nf_internal set should not do overflow checking, resolves #30889
* do not convert succ/pred into add/sub nodes if nf_internal is set

git-svn-id: trunk@34896 -

florian 8 年之前
父节点
当前提交
6d6a45c034
共有 4 个文件被更改,包括 22 次插入3 次删除
  1. 1 0
      .gitattributes
  2. 2 2
      compiler/ncgadd.pas
  3. 6 1
      compiler/ninl.pas
  4. 13 0
      tests/webtbs/tw30889.pp

+ 1 - 0
.gitattributes

@@ -15250,6 +15250,7 @@ tests/webtbs/tw30706.pp svneol=native#text/plain
 tests/webtbs/tw3073.pp svneol=native#text/plain
 tests/webtbs/tw3082.pp svneol=native#text/plain
 tests/webtbs/tw3083.pp svneol=native#text/plain
+tests/webtbs/tw30889.pp svneol=native#text/pascal
 tests/webtbs/tw30923.pp svneol=native#text/pascal
 tests/webtbs/tw3093.pp svneol=native#text/plain
 tests/webtbs/tw3101.pp svneol=native#text/plain

+ 2 - 2
compiler/ncgadd.pas

@@ -520,7 +520,7 @@ interface
           checkoverflow and
           (left.resultdef.typ<>pointerdef) and
           (right.resultdef.typ<>pointerdef) and
-          (cs_check_overflow in current_settings.localswitches);
+          (cs_check_overflow in current_settings.localswitches) and not(nf_internal in flags);
 
 {$ifdef cpu64bitalu}
         case nodetype of
@@ -714,7 +714,7 @@ interface
          checkoverflow and
           (left.resultdef.typ<>pointerdef) and
           (right.resultdef.typ<>pointerdef) and
-          (cs_check_overflow in current_settings.localswitches);
+          (cs_check_overflow in current_settings.localswitches) and not(nf_internal in flags);
 
        if nodetype<>subn then
         begin

+ 6 - 1
compiler/ninl.pas

@@ -3472,7 +3472,7 @@ implementation
                 because it's too complex to handle correctly otherwise }
 {$ifndef jvm}
               { enums are class instances in the JVM -> always need conversion }
-              if ([cs_check_overflow,cs_check_range]*current_settings.localswitches)<>[] then
+              if (([cs_check_overflow,cs_check_range]*current_settings.localswitches)<>[]) and not(nf_internal in flags) then
 {$endif}
                 begin
                   { create constant 1 }
@@ -3491,6 +3491,11 @@ implementation
                   else
                     hp:=caddnode.create(subn,left,hp);
 
+                  { the condition above is not tested for jvm, so we need to avoid overflow checks here
+                    by setting nf_internal for the add/sub node as well }
+                  if nf_internal in flags then
+                    include(hp.flags,nf_internal);
+
                   { assign result of addition }
                   if not(is_integer(resultdef)) then
                     inserttypeconv(hp,corddef.create(

+ 13 - 0
tests/webtbs/tw30889.pp

@@ -0,0 +1,13 @@
+{$OVERFLOWCHECKS+}
+{$mode objfpc}
+program project1;
+
+var
+  c: Cardinal;
+  i: Integer;
+
+begin
+  i := 1;
+  for c := 0 to i do
+    WriteLn(i);
+end.