From 7c92412c74ca66345a3f5284e07596c3a138f078 Mon Sep 17 00:00:00 2001 From: pierre Date: Thu, 15 Nov 2018 16:57:57 +0000 Subject: [PATCH] Avoid overflow error in riscv code generator git-svn-id: trunk@40318 - --- compiler/riscv/nrvadd.pas | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/compiler/riscv/nrvadd.pas b/compiler/riscv/nrvadd.pas index 291fd037c3..ac2d2186f7 100644 --- a/compiler/riscv/nrvadd.pas +++ b/compiler/riscv/nrvadd.pas @@ -88,7 +88,10 @@ implementation hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false); if (right.location.loc=LOC_CONSTANT) and - (not is_imm12(-right.location.value)) then + { right.location.value might be $8000000000000000, + and its minus value generates an overflow here } + {$ifopt Q+} ((right.location.value = int64($8000000000000000)) or {$endif} + (not is_imm12(-right.location.value)) {$ifopt Q+}){$endif} then hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,false); if right.location.loc=LOC_CONSTANT then @@ -103,7 +106,10 @@ implementation hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false); if (right.location.loc=LOC_CONSTANT) and - (not is_imm12(-right.location.value)) then + { right.location.value might be $8000000000000000, + and its minus value generates an overflow here } + {$ifopt Q+} ((right.location.value = int64($8000000000000000)) or {$endif} + (not is_imm12(-right.location.value)) {$ifopt Q+}){$endif} then hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,false); if right.location.loc=LOC_CONSTANT then