Avoid generating invalid .sym files if header ends with a partial declaration.

The part of the declaration within the header could be ignored on subsequent compilations using the .sym file, which could lead to errors or misbehavior.

(This also applies to headers that end in the middle of a _Static_assert(...) or segment directive.)
This commit is contained in:
Stephen Heumann 2022-11-26 00:18:57 -06:00
parent 92a3af1d5f
commit 2bf3862e5d
3 changed files with 10 additions and 3 deletions

View File

@ -3699,6 +3699,7 @@ var
begin {DoDeclaration}
inhibitHeader := true; {block imbedded includes in headers}
if token.kind = _Static_assertsy then begin
DoStaticAssert;
goto 4;
@ -3713,7 +3714,6 @@ startLine := lineNumber;
if not doingFunction then {handle any segment statements}
while token.kind = segmentsy do
SegmentStatement;
inhibitHeader := true; {block imbedded includes in headers}
lUseGlobalPool := useGlobalPool;
{handle a TypeSpecifier/declarator}
declarationSpecifierFound := token.kind in declarationSpecifiersElement;
@ -4097,8 +4097,8 @@ else {if not isFunction then} begin
1:
doingParameters := lDoingParameters; {restore the status}
useGlobalPool := lUseGlobalPool;
inhibitHeader := false;
4:
inhibitHeader := false;
end; {DoDeclaration}

View File

@ -628,8 +628,13 @@ lb4 lda [p1],Y
jsl ~Dispose
! includeCount := includeCount + 1;
inc includeCount
! if inhibitHeader then
lda inhibitHeader
beq lb4a
! TermHeader;
jsl TermHeader
! goto 1;
brl lab1
lb4a brl lab1
! end; {if}
! end {if}

View File

@ -1974,6 +1974,8 @@ int foo(int[42]);
219. If a function is first declared as "static" and then subsequently redeclared or defined as "extern" or with no storage-class specifier, it should be private to the source file, the same as if it was just declared "static".
220. A header that ended with a partial declaration would not be represented correctly in the .sym file. This could cause errors or misbehavior on subsequent compiles.
-- Bugs from C 2.1.0 that have been fixed -----------------------------------
1. In some situations, fread() reread the first 1K or so of the file.