From 8ac887f4dc03b3ca2066703dcdb99cf12c0bd505 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Tue, 2 Feb 2021 18:26:31 -0600 Subject: [PATCH 1/4] Hexadecimal/octal constants 0x80000000+ should have type unsigned long. They previously had type signed long (with negative values). --- Scanner.pas | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Scanner.pas b/Scanner.pas index fd28a16..3ac0247 100644 --- a/Scanner.pas +++ b/Scanner.pas @@ -3337,7 +3337,7 @@ else if numString[1] <> '0' then begin {convert a decimal integer} token.lval := Convertsl(numString); end; {else} end {else if} -else begin {hex & octal} +else begin {hex, octal, & binary} token.lval := 0; if isHex then begin i := 3; @@ -3392,7 +3392,7 @@ else begin {hex & octal} if long(token.lval).msw <> 0 then isLong := true; if isLong then begin - if unsigned then + if unsigned or (token.lval & $80000000 <> 0) then token.kind := ulongConst else token.kind := longConst; From 1b9ee39de7a1e0c87b7401cbb82afad19bfc33c9 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Tue, 2 Feb 2021 18:28:49 -0600 Subject: [PATCH 2/4] Disallow duplicate suffixes on numeric constants (e.g. "123ulu"). --- Scanner.pas | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Scanner.pas b/Scanner.pas index 3ac0247..691d34a 100644 --- a/Scanner.pas +++ b/Scanner.pas @@ -685,6 +685,7 @@ if list or (numErr <> 0) then begin 153: msg := @'lint: return statement in function declared _Noreturn'; 154: msg := @'lint: function declared _Noreturn can return or has unreachable code'; 155: msg := @'lint: non-void function may not return a value or has unreachable code'; + 156: msg := @'invalid suffix on numeric constant'; otherwise: Error(57); end; {case} writeln(msg^); @@ -3277,14 +3278,17 @@ if c2 in ['e','E'] then begin {handle an exponent} while c2 in ['l','u','L','U'] do {check for long or unsigned} if c2 in ['l','L'] then begin NextChar; - if not isReal then - isLong := true; + if isLong then + FlagError(156); + isLong := true; end {if} else {if c2 in ['u','U'] then} begin NextChar; - unsigned := true; - if isReal then + if unsigned then + FlagError(156) + else if isReal then FlagError(91); + unsigned := true; end; {else} if c2 in ['f','F'] then begin {allow F designator on reals} if unsigned then From 32b0d53b07cbaa3f862369a9df41c0310a5a1a3a Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Tue, 2 Feb 2021 18:36:18 -0600 Subject: [PATCH 3/4] PLD/TCD should invalidate register==DP location correspondences. I don't think this ever comes up in code from the ORCA code generator, but it can in inline assembly. --- Native.pas | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Native.pas b/Native.pas index f79848f..9927b49 100644 --- a/Native.pas +++ b/Native.pas @@ -777,7 +777,7 @@ case p_opcode of m_bcc,m_bcs,m_beq,m_bmi,m_bne,m_bpl,m_bra,m_brl,m_bvs,m_clc,m_cmp_abs, m_cmp_dir,m_cmp_imm,m_cmp_s,m_cpx_imm,m_jml,m_pha,m_phb,m_phd, - m_phx,m_phy,m_plb,m_pld,m_rtl,m_rts,m_sec,m_tcs,m_tcd,d_add,d_pin, + m_phx,m_phy,m_plb,m_rtl,m_rts,m_sec,m_tcs,d_add,d_pin, m_pei_dir,m_cpx_abs,m_cpx_dir,m_cmp_dirx,m_php,m_plp,m_cop,d_wrd: ; m_pea: begin @@ -810,7 +810,7 @@ case p_opcode of end; {if} end; - m_sta_s: begin + m_sta_s,m_pld,m_tcd: begin if aRegister.condition = regLocal then aRegister.condition := regUnknown; if xRegister.condition = regLocal then From 4a95dbc597e3583ef32b0c2c7f7b10c0d208afcc Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Wed, 3 Feb 2021 21:06:58 -0600 Subject: [PATCH 4/4] Give an error if you try to define a macro to + or - on the command line. This affects command lines like: cmpl myprog.c cc=(-da=+) ... Previously, this would be accepted, but a was actually defined to 0 rather than +. Now, this gives an error, consistent with other tokens that are not supported in such definitions on the command line. (Perhaps we should support definitions using any tokens, but that would require bigger code changes.) This also cleans up some related code to avoid possible null-pointer dereferences. --- Scanner.pas | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/Scanner.pas b/Scanner.pas index 691d34a..8316f83 100644 --- a/Scanner.pas +++ b/Scanner.pas @@ -3853,6 +3853,10 @@ repeat bp := pointer(ord4(macros) + hash(mp^.name)); mp^.next := bp^; bp^ := mp; + token.kind := intconst; {create the default value} + token.numString := nil; + token.class := intConstant; + token.ival := 1; if lch = '=' then begin NextCh; {record the value} token.numString := nil; @@ -3876,12 +3880,8 @@ repeat otherwise: ; end; {case} end {if} - else begin - token.kind := intconst; - token.numString := nil; - token.class := intConstant; - token.ival := 0; - end; {else} + else + Error(108); end {else if} else if lch in ['.','0'..'9'] then begin token.name := GetWord; @@ -3891,17 +3891,11 @@ repeat GetString else Error(108); - end {if} - else begin - token.kind := intconst; {create the default value} - token.numString := nil; - token.class := intConstant; - token.ival := 1; - end; {else} + end; {if} new(mp^.tokens); {add the value to the definition} with mp^.tokens^ do begin next := nil; - tokenString := nil; + tokenString := @''; expandEnabled := true; tokenStart := nil; tokenEnd := nil;