diff options
-rw-r--r-- | clang/lib/Lex/PPMacroExpansion.cpp | 11 | ||||
-rw-r--r-- | clang/test/Preprocessor/macro_disable.c | 8 |
2 files changed, 14 insertions, 5 deletions
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index ffae8ab6afb..1c6a5ad0ebc 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -258,10 +258,13 @@ bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier, InstantiationEnd,Identifier.getLength()); Identifier.setLocation(Loc); - // If this is #define X X, we must mark the result as unexpandible. - if (IdentifierInfo *NewII = Identifier.getIdentifierInfo()) - if (getMacroInfo(NewII) == MI) - Identifier.setFlag(Token::DisableExpand); + // If this is a disabled macro or #define X X, we must mark the result as + // unexpandable. + if (IdentifierInfo *NewII = Identifier.getIdentifierInfo()) { + if (MacroInfo *NewMI = getMacroInfo(NewII)) + if (!NewMI->isEnabled() || NewMI == MI) + Identifier.setFlag(Token::DisableExpand); + } // Since this is not an identifier token, it can't be macro expanded, so // we're done. diff --git a/clang/test/Preprocessor/macro_disable.c b/clang/test/Preprocessor/macro_disable.c index 95f4784398e..d7859dca77e 100644 --- a/clang/test/Preprocessor/macro_disable.c +++ b/clang/test/Preprocessor/macro_disable.c @@ -34,4 +34,10 @@ a: M_0(1)(2)(3)(4)(5); b: M_0(5)(4)(3)(2)(1); // CHECK: a: 2 + M_0(3)(4)(5); -// CHECK: b: 4 + 4 + 3 + 2 + 1 + M_0(3)(2)(1);
\ No newline at end of file +// CHECK: b: 4 + 4 + 3 + 2 + 1 + M_0(3)(2)(1); + +#define n(v) v +#define l m +#define m l a +c: n(m) X +// CHECK: c: m a X |