From 6c71fd461daf8161fce6e1d4242a1e8b33f21271 Mon Sep 17 00:00:00 2001 From: florian Date: Fri, 24 Jan 2020 21:39:07 +0000 Subject: [PATCH] * avoid internalerror for dec/inc(...,v) with v>high(int64), resolves #35298 git-svn-id: trunk@44031 - --- .gitattributes | 1 + compiler/ncginl.pas | 4 +++- tests/webtbs/tw35298.pp | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/webtbs/tw35298.pp diff --git a/.gitattributes b/.gitattributes index 88862afaad..c4a9a7003f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -17904,6 +17904,7 @@ tests/webtbs/tw3523.pp svneol=native#text/plain tests/webtbs/tw35233.pp svneol=native#text/plain tests/webtbs/tw35272.pp svneol=native#text/plain tests/webtbs/tw3529.pp svneol=native#text/plain +tests/webtbs/tw35298.pp svneol=native#text/pascal tests/webtbs/tw3531.pp svneol=native#text/plain tests/webtbs/tw3533.pp svneol=native#text/plain tests/webtbs/tw3534.pp svneol=native#text/plain diff --git a/compiler/ncginl.pas b/compiler/ncginl.pas index b2eb48cede..acc44df296 100644 --- a/compiler/ncginl.pas +++ b/compiler/ncginl.pas @@ -451,7 +451,9 @@ implementation begin {$if not defined(cpu64bitalu) and not defined(cpuhighleveltarget)} if def_cgsize(left.resultdef) in [OS_64,OS_S64] then - cg64.a_op64_const_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],def_cgsize(left.resultdef),addvalue,tcallparanode(left).left.location) + { use addvalue.svalue here to avoid an internal error if addvalue is unsigned and overflows int64, see #35298, + we are only interested in the bit pattern here } + cg64.a_op64_const_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],def_cgsize(left.resultdef),addvalue.svalue,tcallparanode(left).left.location) else {$endif not cpu64bitalu and not cpuhighleveltarget} hlcg.a_op_const_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],left.resultdef, diff --git a/tests/webtbs/tw35298.pp b/tests/webtbs/tw35298.pp new file mode 100644 index 0000000000..8377b58b84 --- /dev/null +++ b/tests/webtbs/tw35298.pp @@ -0,0 +1,16 @@ +{$MODE DELPHI} +{$RANGECHECKS OFF} +{$OVERFLOWCHECKS OFF} + +function SplitMix64(var X: UInt64) : UInt64; +var + Z: UInt64; +begin + Inc(X, UInt64($9E3779B97F4A7C15)); + Z := (X xor (X shr 30)) * UInt64($BF58476D1CE4E5B9); + Z := (Z xor (Z shr 27)) * UInt64($94D049BB133111EB); + Result := Z xor (Z shr 31); +end; + +begin +end.