From: Chris Lattner Date: Fri, 26 Mar 2010 17:49:16 +0000 (+0000) Subject: fix a case where macro expansion should be disabled, patch by X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8ff66de0d036842450eb979882f826d5252100f4;p=clang fix a case where macro expansion should be disabled, patch by Abramo Bagnara! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99626 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp index ffae8ab6af..1c6a5ad0eb 100644 --- a/lib/Lex/PPMacroExpansion.cpp +++ b/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/test/Preprocessor/macro_disable.c b/test/Preprocessor/macro_disable.c index 95f4784398..d7859dca77 100644 --- a/test/Preprocessor/macro_disable.c +++ b/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