From 5d7c0028195bfd04cf488808cc494dbb113e3125 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 13 Feb 2022 16:33:43 -0600 Subject: [PATCH] Fix bug causing some #undefs to be ignored when using a sym file. This would occur if the macro had already been saved in the sym file and the #undef occurred before a subsequent #include that was also recorded in the sym file. The solution is simply to terminate sym file generation if an #undef of an already-saved macro is encountered. Here is an example showing the problem: test.c: #include "test1.h" #undef x #include "test2.h" int main(void) { #ifdef x return x; #else return y; #endif } test1.h: #define x 27 test2.h: #define y 6 --- Header.pas | 2 +- Scanner.pas | 2 ++ cc.notes | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Header.pas b/Header.pas index b80a242..9c3e27d 100644 --- a/Header.pas +++ b/Header.pas @@ -18,7 +18,7 @@ uses CCommon, MM, Scanner, Symbol, CGI; {$segment 'SCANNER'} const - symFileVersion = 21; {version number of .sym file format} + symFileVersion = 22; {version number of .sym file format} var inhibitHeader: boolean; {should .sym includes be blocked?} diff --git a/Scanner.pas b/Scanner.pas index 3bd09db..bab212a 100644 --- a/Scanner.pas +++ b/Scanner.pas @@ -2943,6 +2943,8 @@ var bPtr^ := mPtr^.next else lastPtr^.next := mPtr^.next; + if mPtr^.saved then + TermHeader; end; {else} goto 1; end; {if} diff --git a/cc.notes b/cc.notes index 5260f3b..d16ad0d 100644 --- a/cc.notes +++ b/cc.notes @@ -1775,6 +1775,8 @@ int foo(int[42]); 179. Macro definitions or header search paths specified via the cc= portion of the command line could be saved in the .sym file and applied to subsequent compilations, even if they were no longer specified on the command line. +180. Certain #undef directives might be ignored when using a .sym file. + -- Bugs from C 2.1.0 that have been fixed ----------------------------------- 1. In some situations, fread() reread the first 1K or so of the file.