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.
This commit is contained in:
Stephen Heumann 2021-02-13 15:36:54 -06:00
parent a3050c76a9
commit 32ae4c2e17
1 changed files with 23 additions and 6 deletions

View File

@ -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