diff options
author | Faisal Vali <faisalv@yahoo.com> | 2017-07-25 03:15:36 +0000 |
---|---|---|
committer | Faisal Vali <faisalv@yahoo.com> | 2017-07-25 03:15:36 +0000 |
commit | 6bf67915381d8cfeb52789b978e75c1dde59f7e4 (patch) | |
tree | 32605bd956c03264ae974f9ce776f81292bcc617 /clang/lib/Lex/PPDirectives.cpp | |
parent | 6f7befd10f071e50266b56c8c53ec8b248b60689 (diff) | |
download | bcm5719-llvm-6bf67915381d8cfeb52789b978e75c1dde59f7e4.tar.gz bcm5719-llvm-6bf67915381d8cfeb52789b978e75c1dde59f7e4.zip |
[NFC] Use RAII to un-poison and then re-poison __VA_ARGS__
- This will also be used for the forthcoming __VA_OPT__ feature approved for C++2a.
- recommended by rsmith during his review of the __VA_OPT__ patch (https://reviews.llvm.org/D35782)
llvm-svn: 308948
Diffstat (limited to 'clang/lib/Lex/PPDirectives.cpp')
-rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index b2450f516ba..6b09398e468 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -33,6 +33,7 @@ #include "clang/Lex/PreprocessorOptions.h" #include "clang/Lex/PTHLexer.h" #include "clang/Lex/Token.h" +#include "clang/Lex/VariadicMacroSupport.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" @@ -2290,6 +2291,10 @@ MacroInfo *Preprocessor::ReadOptionalMacroParameterListAndBody( Token Tok; LexUnexpandedToken(Tok); + // Used to un-poison and then re-poison identifiers of the __VA_ARGS__ ilk + // within their appropriate context. + VariadicMacroScopeGuard VariadicMacroScopeGuard(*this); + // If this is a function-like macro definition, parse the argument list, // marking each of the identifiers as being used as macro arguments. Also, // check other constraints on the first token of the macro body. @@ -2314,14 +2319,14 @@ MacroInfo *Preprocessor::ReadOptionalMacroParameterListAndBody( return nullptr; } - // If this is a definition of a variadic C99 function-like macro, not using - // the GNU named varargs extension, enabled __VA_ARGS__. + // If this is a definition of an ISO C/C++ variadic function-like macro (not + // using the GNU named varargs extension) inform our variadic scope guard + // which un-poisons and re-poisons certain identifiers (e.g. __VA_ARGS__) + // allowed only within the definition of a variadic macro. - // "Poison" __VA_ARGS__, which can only appear in the expansion of a macro. - // This gets unpoisoned where it is allowed. - assert(Ident__VA_ARGS__->isPoisoned() && "__VA_ARGS__ should be poisoned!"); - if (MI->isC99Varargs()) - Ident__VA_ARGS__->setIsPoisoned(false); + if (MI->isC99Varargs()) { + VariadicMacroScopeGuard.enterScope(); + } // Read the first token after the arg list for down below. LexUnexpandedToken(Tok); @@ -2431,9 +2436,6 @@ MacroInfo *Preprocessor::ReadOptionalMacroParameterListAndBody( } else { Diag(Tok, diag::err_pp_stringize_not_parameter) << LastTok.is(tok::hashat); - - // Disable __VA_ARGS__ again. - Ident__VA_ARGS__->setIsPoisoned(true); return nullptr; } } @@ -2448,9 +2450,6 @@ MacroInfo *Preprocessor::ReadOptionalMacroParameterListAndBody( } } MI->setDefinitionEndLoc(LastTok.getLocation()); - // Disable __VA_ARGS__ again. - Ident__VA_ARGS__->setIsPoisoned(true); - return MI; } /// HandleDefineDirective - Implements \#define. This consumes the entire macro |