Give an error if assembly code tries to use direct page addressing for a local variable that is out of range.

This could previously cause bad code to be produced with no error reported.
This commit is contained in:
Stephen Heumann 2023-03-04 21:06:07 -06:00
parent a985a9ca7a
commit 85890e0b6b
4 changed files with 11 additions and 1 deletions

View File

@ -33,6 +33,7 @@ const
cge1 = 57; {compiler error}
cge2 = 58; {implementation restriction: too many local labels}
cge3 = 60; {implementation restriction: string space exhausted}
cge4 = 188; {local variable out of range for DP addressing}
{65816 native code generation}
{----------------------------}

View File

@ -6776,8 +6776,12 @@ procedure GenTree {op: icptr};
opcode := op^.s;
if opcode < 256 then
opcode := opcode | asmFlag;
if op^.slab <> 0 then
if op^.slab <> 0 then begin
val := val+LabelToDisp(op^.slab);
if mode = direct then
if (val > 255) or (val < 0) then
Error(cge4);
end; {if}
if mode in [relative,longrelative] then
GenNative(opcode, mode, op^.llab, op^.lab, op^.q)
else if (mode = longabsolute) and (op^.llab <> 0) then

View File

@ -803,6 +803,7 @@ if list or (numErr <> 0) then begin
185: msg := @'lint: unused variable: ';
186: msg := @'lint: implicit conversion changes value of constant';
187: msg := @'expression has incomplete struct or union type';
188: msg := @'local variable used in asm statement is out of range for addressing mode';
end; {case}
if extraStr <> nil then begin
extraStr^ := concat(msg^,extraStr^);

View File

@ -271,6 +271,10 @@ The unary conversion rules have been modified to convert values of type char or
In the binary conversions, if either operand has a floating-point type, the semantic type is the largest floating-point type of either operand. However, floating-point operations are always evaluated with the range and precision of the SANE extended format.
p. 333,334
If assembly code attempts to access a local variable using direct page addressing when its location is more than 255 bytes from the start of the direct page, ORCA/C will now detect and report this error ("local variable used in asm statement is out of range for addressing mode").
p. 337
The ORCA/C compiler is intended as a faithful implementation of ANSI C with some extensions, but there have always been some library functions from ANSI C that were missing in ORCA/C. Chapter 19 should start with a summary of these omissions.