Avoid incorrectly setting lastwasconst.

This could happen in some cases where one subexpression of a larger expression was a constant. One effect of this was to cause spurious "lint: implicit conversion changes value of constant" messages in certain cases (when that lint check was enabled). It may also have caused certain errors to be missed in other situations.
This commit is contained in:
Stephen Heumann 2023-02-28 22:36:42 -06:00
parent bda54c0a79
commit ea623d38fc

View File

@ -2872,6 +2872,7 @@ var
doingScalar: boolean; {temp; for assignment operators} doingScalar: boolean; {temp; for assignment operators}
et: baseTypeEnum; {temp storage for a base type} et: baseTypeEnum; {temp storage for a base type}
i: integer; {loop variable} i: integer; {loop variable}
isConst: boolean; {is this a constant?}
isNullPtrConst: boolean; {is this a null pointer constant?} isNullPtrConst: boolean; {is this a null pointer constant?}
isVolatile: boolean; {is this a volatile op?} isVolatile: boolean; {is this a volatile op?}
lType: typePtr; {type of operands} lType: typePtr; {type of operands}
@ -3548,7 +3549,6 @@ var
GenTool(pc_tl1, ftype^.toolNum, long(ftype^.ftype^.size).lsw, GenTool(pc_tl1, ftype^.toolNum, long(ftype^.ftype^.size).lsw,
ftype^.dispatcher); ftype^.dispatcher);
expressionType := ftype^.fType; expressionType := ftype^.fType;
lastWasConst := false;
CheckForIncompleteStructType; CheckForIncompleteStructType;
end; {else} end; {else}
end; {FunctionCall} end; {FunctionCall}
@ -3674,7 +3674,7 @@ var
begin {GenerateCode} begin {GenerateCode}
lastwasconst := false; isConst := false;
isNullPtrConst := false; isNullPtrConst := false;
case tree^.token.kind of case tree^.token.kind of
@ -3737,7 +3737,7 @@ case tree^.token.kind of
intConst,uintConst,ushortConst,charConst,scharConst,ucharConst: begin intConst,uintConst,ushortConst,charConst,scharConst,ucharConst: begin
Gen1t(pc_ldc, tree^.token.ival, cgWord); Gen1t(pc_ldc, tree^.token.ival, cgWord);
lastwasconst := true; isConst := true;
lastconst := tree^.token.ival; lastconst := tree^.token.ival;
isNullPtrConst := tree^.token.ival = 0; isNullPtrConst := tree^.token.ival = 0;
if tree^.token.kind = intConst then if tree^.token.kind = intConst then
@ -3760,7 +3760,7 @@ case tree^.token.kind of
expressionType := longPtr expressionType := longPtr
else else
expressionType := ulongPtr; expressionType := ulongPtr;
lastwasconst := true; isConst := true;
lastconst := tree^.token.lval; lastconst := tree^.token.lval;
isNullPtrConst := tree^.token.lval = 0; isNullPtrConst := tree^.token.lval = 0;
end; {case longConst} end; {case longConst}
@ -3772,7 +3772,7 @@ case tree^.token.kind of
else else
expressionType := ulonglongPtr; expressionType := ulonglongPtr;
if (tree^.token.qval.hi = 0) and (tree^.token.qval.lo >= 0) then begin if (tree^.token.qval.hi = 0) and (tree^.token.qval.lo >= 0) then begin
lastwasconst := true; isConst := true;
lastconst := tree^.token.qval.lo; lastconst := tree^.token.qval.lo;
end; {if} end; {if}
isNullPtrConst := (tree^.token.qval.hi = 0) and (tree^.token.qval.lo = 0); isNullPtrConst := (tree^.token.qval.hi = 0) and (tree^.token.qval.lo = 0);
@ -4814,6 +4814,7 @@ case tree^.token.kind of
if doDispose then if doDispose then
dispose(tree); dispose(tree);
lastWasNullPtrConst := isNullPtrConst; lastWasNullPtrConst := isNullPtrConst;
lastWasConst := isConst;
end; {GenerateCode} end; {GenerateCode}