From ea32ddd5b2b254d88744fef303f8a13296ad20e7 Mon Sep 17 00:00:00 2001 From: florian Date: Thu, 16 Aug 2018 20:45:36 +0000 Subject: [PATCH] * avoid overflows of execution weight git-svn-id: trunk@39623 - --- compiler/cutils.pas | 26 ++++++++++++++++++++++++++ compiler/pass_2.pas | 4 +--- compiler/rgobj.pas | 8 ++++++-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/compiler/cutils.pas b/compiler/cutils.pas index 26b9b3838f..c7467d64f1 100644 --- a/compiler/cutils.pas +++ b/compiler/cutils.pas @@ -42,9 +42,11 @@ interface {# Returns the minimal value between @var(a) and @var(b) } function min(a,b : longint) : longint;{$ifdef USEINLINE}inline;{$endif} function min(a,b : int64) : int64;{$ifdef USEINLINE}inline;{$endif} + function min(a,b : qword) : qword;{$ifdef USEINLINE}inline;{$endif} {# Returns the maximum value between @var(a) and @var(b) } function max(a,b : longint) : longint;{$ifdef USEINLINE}inline;{$endif} function max(a,b : int64) : int64;{$ifdef USEINLINE}inline;{$endif} + function max(a,b : qword) : qword;{$ifdef USEINLINE}inline;{$endif} { These functions are intenionally put here and not in the constexp unit. Since Tconstexprint may be automatically converted to int, which causes @@ -227,6 +229,18 @@ implementation end; + function min(a,b : qword) : qword; + { + return the minimal of a and b + } + begin + if a<=b then + min:=a + else + min:=b; + end; + + function max(a,b : longint) : longint;{$ifdef USEINLINE}inline;{$endif} { return the maximum of a and b @@ -251,6 +265,18 @@ implementation end; + function max(a,b : qword) : qword;{$ifdef USEINLINE}inline;{$endif} + { + return the maximum of a and b + } + begin + if a>=b then + max:=a + else + max:=b; + end; + + function max(const a,b : Tconstexprint) : Tconstexprint;{$ifdef USEINLINE}inline;{$endif} { return the maximum of a and b diff --git a/compiler/pass_2.pas b/compiler/pass_2.pas index 3b3301afd6..c60d71514a 100644 --- a/compiler/pass_2.pas +++ b/compiler/pass_2.pas @@ -58,9 +58,7 @@ procedure secondpass(p : tnode); implementation uses -{$ifdef EXTDEBUG} cutils, -{$endif} globtype,verbose, globals, aasmdata, @@ -194,7 +192,7 @@ implementation current_settings.localswitches:=p.localswitches; codegenerror:=false; if assigned(p.optinfo) then - cg.executionweight:=p.optinfo^.executionweight + cg.executionweight:=min(p.optinfo^.executionweight,QWord(high(cg.executionweight))) else cg.executionweight:=100; {$ifdef EXTDEBUG} diff --git a/compiler/rgobj.pas b/compiler/rgobj.pas index 34643805e0..553d5ac949 100644 --- a/compiler/rgobj.pas +++ b/compiler/rgobj.pas @@ -830,8 +830,12 @@ unit rgobj; if supreg>=first_imaginary then with reginfo[supreg] do begin - // if aweight>weight then - inc(weight,aweight); + { avoid overflow } + if high(weight)-aweight