From 32ae4c2e171e70292bbe9b86aa52bc80763a2ac1 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sat, 13 Feb 2021 15:36:54 -0600 Subject: [PATCH] Allow unsigned constants in "address+constant" constant expressions. This affected initializers like the following: static int a[50]; static int *ip = &a[0] + 2U; Also, introduce some basic range checks for calculations that are obviously outside the 65816's address space. --- Parser.pas | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/Parser.pas b/Parser.pas index 3dd0015..13f194a 100644 --- a/Parser.pas +++ b/Parser.pas @@ -1852,8 +1852,13 @@ var size := rtree^.token.ival else if rtree^.token.kind in [longconst,ulongconst] then size := rtree^.token.lval - else if rtree^.token.kind in [longlongconst,ulonglongconst] then - size := rtree^.token.qval.lo + else if rtree^.token.kind in [longlongconst,ulonglongconst] then begin + size := rtree^.token.qval.lo; + with rtree^.token.qval do + if not (((hi = 0) and (lo & $ff000000 = 0)) or + ((hi = -1) and (lo & $ff000000 = $ff000000))) then + Error(6); + end {else if} else begin Error(18); errorFound := true; @@ -2085,13 +2090,25 @@ var operator := tree^.token.kind; while operator in [plusch,minusch] do begin with tree^.right^.token do - if kind in [intConst,longConst,longlongConst] then begin + if kind in [intConst,uintconst,longConst,ulongconst, + longlongConst,ulonglongconst] then begin if kind = intConst then offSet2 := ival - else if kind = longConst then - offset2 := lval - else {if kind = longlongConst then} + else if kind = uintConst then + offset2 := ival & $0000ffff + else if kind in [longConst,ulongconst] then begin + offset2 := lval; + if (lval & $ff000000 <> 0) + and (lval & $ff000000 <> $ff000000) then + Error(6); + end {else if} + else {if kind = longlongConst then} begin offset2 := qval.lo; + with qval do + if not (((hi = 0) and (lo & $ff000000 = 0)) or + ((hi = -1) and (lo & $ff000000 = $ff000000))) then + Error(6); + end; {else} if operator = plusch then offset := offset + offset2 else