From 2bf3862e5d1fddf4ad0dce9c6d4c1eb34c334a37 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sat, 26 Nov 2022 00:18:57 -0600 Subject: [PATCH] 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.) --- Parser.pas | 4 ++-- Scanner.asm | 7 ++++++- cc.notes | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Parser.pas b/Parser.pas index 32d601d..5099be6 100644 --- a/Parser.pas +++ b/Parser.pas @@ -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} diff --git a/Scanner.asm b/Scanner.asm index 515779d..c3765c2 100644 --- a/Scanner.asm +++ b/Scanner.asm @@ -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} diff --git a/cc.notes b/cc.notes index ba554db..d6188b4 100644 --- a/cc.notes +++ b/cc.notes @@ -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.