From e8b860f89ab2d71e6877d8ae60137cff373b3780 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sat, 13 Feb 2021 21:14:26 -0600 Subject: [PATCH] Do not corrupt long long expressions that cannot be evaluated at compile time. The changes to constant expressions were not allowing the unsupported constant expressions to be evaluated at run time when they appear in regular code. --- Expression.pas | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/Expression.pas b/Expression.pas index e984d5a..7eebcf1 100644 --- a/Expression.pas +++ b/Expression.pas @@ -1230,6 +1230,7 @@ var goto 1; end; {if} end; {if} + if kindRight in [intconst,uintconst,longconst,ulongconst, longlongconst,ulonglongconst] then begin if kindLeft in [intconst,uintconst,longconst,ulongconst, @@ -1248,10 +1249,6 @@ var GetLongLongVal(llop1, op^.left^.token); GetLongLongVal(llop2, op^.right^.token); - dispose(op^.right); - op^.right := nil; - dispose(op^.left); - op^.left := nil; case op^.token.kind of barbarop : begin {||} @@ -1296,12 +1293,22 @@ var minusch, {-} asteriskch, {*} slashch, {/} - percentch: {%} - if not (kind in [normalExpression,autoInitializerExpression]) - then - Error(157); + percentch: begin {%} + if kind in [normalExpression,autoInitializerExpression] + then goto 1; + Error(157); + llop1 := longlong0; + op1 := 0; + if op^.token.kind in [ltch,gtch,lteqop,gteqop] then + ekind := intconst; + end; otherwise: Error(57); end; {case} + + dispose(op^.right); + op^.right := nil; + dispose(op^.left); + op^.left := nil; op^.token.kind := ekind; if ekind in [longlongconst,ulonglongconst] then begin op^.token.qval := llop1; @@ -1314,6 +1321,7 @@ var goto 1; end; {if} end; {if} + if op^.right^.token.kind in [intconst,uintconst,longconst,ulongconst,doubleconst] then if op^.left^.token.kind in @@ -1378,6 +1386,7 @@ var end; {else} goto 1; end; {if} + if op^.right^.token.kind in [intconst,uintconst,longconst, ulongconst,longlongconst,ulonglongconst,doubleconst] then if op^.left^.token.kind in [intconst,uintconst,longconst,