Add a new #pragma ignore option to treat char and unsigned char as compatible.

This is contrary to the C standards, but ORCA/C historically permitted it (as do some other compilers), and I think there is a fair amount of existing code that relies on it.
This commit is contained in:
Stephen Heumann 2020-05-22 17:11:13 -05:00
parent 5d64436e6e
commit f0a3808c18
3 changed files with 14 additions and 4 deletions

View File

@ -872,7 +872,8 @@ procedure EndInclude {chPtr: ptr};
| (ord(allowLongIntChar) << 1)
| (ord(allowTokensAfterEndif) << 2)
| (ord(allowSlashSlashComments) << 3)
| (ord(allowMixedDeclarations) << 4));
| (ord(allowMixedDeclarations) << 4)
| (ord(looseCharTypeChecks) << 5));
p_segment: begin
for i := 1 to 10 do begin
@ -1524,6 +1525,7 @@ var
allowSlashSlashComments := odd(i >> 3);
allowMixedDeclarations := odd(i >> 4);
c99Scope := allowMixedDeclarations;
looseCharTypeChecks := odd(i >> 5);
end;
p_segment: begin

View File

@ -89,6 +89,7 @@ var
{Note: The following two are set together}
allowMixedDeclarations: boolean; {allow mixed declarations & stmts (C99)?}
c99Scope: boolean; {follow C99 rules for block scopes?}
looseCharTypeChecks: boolean; {treat char and unsigned char as compatible?}
{---------------------------------------------------------------}
@ -2981,6 +2982,7 @@ if ch in ['a','d','e','i','l','p','u','w'] then begin
allowTokensAfterEndif := odd(val >> 2);
allowSlashSlashComments := odd(val >> 3);
allowMixedDeclarations := odd(val >> 4);
looseCharTypeChecks := odd(val >> 5);
if allowMixedDeclarations <> c99Scope then begin
if doingFunction then
Error(126)
@ -3672,6 +3674,7 @@ allowTokensAfterEndif := false; {allow tokens after #endif}
allowSlashSlashComments := true; {allow // comments}
allowMixedDeclarations := true; {allow mixed declarations & stmts (C99)}
c99Scope := true; {follow C99 rules for block scopes}
looseCharTypeChecks := true; {make char and unsigned char compatible}
foundFunction := false; {no functions found so far}
fileList := nil; {no included files}
gettingFileName := false; {not in GetFileName}

View File

@ -383,9 +383,14 @@ else
case kind1 of
scalarType:
if kind2 = scalarType then
CompTypes :=
(t1^.baseType = t2^.baseType) and (t1^.cType = t2^.cType)
if kind2 = scalarType then begin
CompTypes := t1^.baseType = t2^.baseType;
if t1^.cType <> t2^.cType then
if not (looseCharTypeChecks
and (t1^.cType in [ctChar, ctUChar])
and (t2^.cType in [ctChar, ctUChar])) then
CompTypes := false;
end {if}
else if kind2 = enumType then
CompTypes := (t1^.baseType = cgWord) and (t1^.cType = ctInt);