From deca73d2332a6ccd570603081b00d6bdff7c6596 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Tue, 24 May 2022 22:22:37 -0500 Subject: [PATCH] Properly expand macros that have the same name as a keyword or typedef. If such macros were used within other macros, they would generally not be expanded, due to the order in which operations were evaluated during preprocessing. This is actually an issue that was fixed by the changes from ORCA/C 2.1.0 to 2.1.1 B3, but then broken again by commit d0b4b75970. Here is an example with the name of a keyword: #define X long int #define long X x; int main(void) { return sizeof(x); /* should be sizeof(int) */ } Here is an example with the name of a typedef: typedef short T; #define T long #define X T X x; int main(void) { return sizeof(x); /* should be sizeof(long) */ } --- Scanner.pas | 14 +++++++------- cc.notes | 2 ++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Scanner.pas b/Scanner.pas index 4cf05e3..d483c7b 100644 --- a/Scanner.pas +++ b/Scanner.pas @@ -4873,13 +4873,6 @@ if tokenList <> nil then begin {get a token put back by a macro} dispose(tPtr); if token.kind = typedef then {allow for typedefs in a macro} token.kind := ident; - if token.kind = ident then begin - CopyString(@workString, token.name); - lExpandMacros := expandMacros; - expandMacros := false; - CheckIdentifier; - expandMacros := lExpandMacros; - end; {if} { dead code if token.kind = ident then if FindSymbol(token,allSpaces,false,false) <> nil then @@ -4926,6 +4919,13 @@ if tokenList <> nil then begin {get a token put back by a macro} goto 4; end; {if} end; {if} + if token.kind = ident then begin + CopyString(@workString, token.name); + lExpandMacros := expandMacros; + expandMacros := false; + CheckIdentifier; + expandMacros := lExpandMacros; + end; {if} goto 2; end; {if} 5: {skip white space} diff --git a/cc.notes b/cc.notes index ac8e3ee..8a0df2f 100644 --- a/cc.notes +++ b/cc.notes @@ -1803,6 +1803,8 @@ int foo(int[42]); 183. The # preprocessor operator would not work correctly on tokens that had been produced by the ## preprocessor operator, tokens that were split over two or more lines using line continuations, or tokens represented using trigraphs. +184. If a macro was declared with the same name as a keyword or a typedef, and that name was also used within another macro, the first macro would not be correctly expanded within invocations of the second macro. (This is a bug that was previously fixed in ORCA/C 2.1.1 B3, but was subsequently reintroduced.) + -- Bugs from C 2.1.0 that have been fixed ----------------------------------- 1. In some situations, fread() reread the first 1K or so of the file.