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
This commit is contained in:
Stephen Heumann 2022-02-13 16:33:43 -06:00
parent b231782442
commit 5d7c002819
3 changed files with 5 additions and 1 deletions

View File

@ -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?}

View File

@ -2943,6 +2943,8 @@ var
bPtr^ := mPtr^.next
else
lastPtr^.next := mPtr^.next;
if mPtr^.saved then
TermHeader;
end; {else}
goto 1;
end; {if}

View File

@ -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.