Allow function pointer == NULL comparisons under strict type checks.

These were improperly being flagged as an error, because (void*)0 was not being recognized as a null pointer constant in this context.
This commit is contained in:
Stephen Heumann 2024-08-02 20:26:40 -05:00
parent a9e0b13e1c
commit 5f59f152ed
2 changed files with 8 additions and 9 deletions

View File

@ -2899,8 +2899,6 @@ var
kind: typeKind; {temp type kind}
size: longint; {size of an array element}
t1: integer; {temporary work space label number}
tlastwasconst: boolean; {temp lastwasconst}
tlastconst: longint; {temp lastconst}
tlastWasNullPtrConst: boolean; {temp lastWasNullPtrConst}
tp: tokenPtr; {work pointer}
tType: typePtr; {temp type of operand}
@ -3604,7 +3602,7 @@ var
if not looseTypeChecks then begin
if not equality then
Error(47)
else if (not tlastwasconst) or (tlastconst <> 0) then
else if not tlastWasNullPtrConst then
if t2^.ptype^.kind = functionType then
Error(47);
end {if}
@ -3614,7 +3612,7 @@ var
if not looseTypeChecks then begin
if not equality then
Error(47)
else if (not lastwasconst) or (lastconst <> 0) then
else if not lastWasNullPtrConst then
if t1^.ptype^.kind = functionType then
Error(47);
end {if}
@ -3623,13 +3621,13 @@ var
Error(47);
t2 := ulongPtr;
end {if}
else if (not lastwasconst) or (lastconst <> 0)
else if not lastWasNullPtrConst
or (not equality and not looseTypeChecks) then
Error(47);
t1 := ulongPtr;
end {if}
else if expressionType^.kind in [pointerType,arrayType] then begin
if (not equality) or (not tlastwasconst) or (tlastconst <> 0) then
else if t2^.kind in [pointerType,arrayType] then begin
if not equality or not tlastWasNullPtrConst then
Error(47);
t2 := ulongPtr;
end; {else if}
@ -4549,8 +4547,7 @@ case tree^.token.kind of
exceqop: begin {!=}
GenerateCode(tree^.left);
lType := expressionType;
tlastwasconst := lastwasconst;
tlastconst := lastconst;
tLastWasNullPtrConst := lastWasNullPtrConst;
GenerateCode(tree^.right);
CompareCompatible(ltype, expressionType, true);
if tree^.token.kind = eqeqop then

View File

@ -1628,6 +1628,8 @@ If you use #pragma debug 0x0010 to enable stack check debug code, the compiler w
19. When numeric tokens beginning with . were used as operands to the ## preprocessing operator, they behaved as if they started with a leading 0, which could lead to an incorrect result (e.g. 123##.456 became 1230.456).
20. When using strict type checks, == or != comparisons between a function pointer and NULL or (void*)0 would cause a spurious error.
-- Bugs from C 2.1.1 B3 that have been fixed in C 2.2.0 ---------------------
1. There were various bugs that could cause incorrect code to be generated in certain cases. Some of these were specific to certain optimization passes, alone or in combination.