diff --git a/.gitattributes b/.gitattributes index 19b1ce508e..2c87ee8da1 100644 --- a/.gitattributes +++ b/.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 diff --git a/compiler/ncgadd.pas b/compiler/ncgadd.pas index 5e3fa3ba40..3cde9f640b 100644 --- a/compiler/ncgadd.pas +++ b/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 diff --git a/compiler/ninl.pas b/compiler/ninl.pas index 2c75ea6d19..a7772cdbf3 100644 --- a/compiler/ninl.pas +++ b/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( diff --git a/tests/webtbs/tw30889.pp b/tests/webtbs/tw30889.pp new file mode 100644 index 0000000000..8a9348a657 --- /dev/null +++ b/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.