diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2013-01-16 19:32:21 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2013-01-16 19:32:21 +0000 |
commit | 6ce0000dd52815db5ad3e7ff67fd14df244a2d81 (patch) | |
tree | a4c5533bc291655897c0519843ca6ae0d909056a /clang/lib/Lex | |
parent | 0fab22544f065c4be06e3f3eda495a76dce17ae7 (diff) | |
download | bcm5719-llvm-6ce0000dd52815db5ad3e7ff67fd14df244a2d81.tar.gz bcm5719-llvm-6ce0000dd52815db5ad3e7ff67fd14df244a2d81.zip |
No longer crashing with an assert when __has_include or __has_include_next is used outside of a preprocessor directive. This fixes PR14837.
llvm-svn: 172639
Diffstat (limited to 'clang/lib/Lex')
-rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Lex/PPMacroExpansion.cpp | 6 | ||||
-rw-r--r-- | clang/lib/Lex/Preprocessor.cpp | 3 |
3 files changed, 11 insertions, 1 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index bdca03637db..7e46a9cc28e 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -24,6 +24,7 @@ #include "clang/Lex/Pragma.h" #include "llvm/ADT/APInt.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/SaveAndRestore.h" using namespace clang; //===----------------------------------------------------------------------===// @@ -2071,6 +2072,7 @@ void Preprocessor::HandleIfdefDirective(Token &Result, bool isIfndef, /// void Preprocessor::HandleIfDirective(Token &IfToken, bool ReadAnyTokensBeforeDirective) { + SaveAndRestore<bool> PPDir(ParsingIfOrElifDirective, true); ++NumIf; // Parse and evaluate the conditional expression. @@ -2162,6 +2164,7 @@ void Preprocessor::HandleElseDirective(Token &Result) { /// HandleElifDirective - Implements the \#elif directive. /// void Preprocessor::HandleElifDirective(Token &ElifToken) { + SaveAndRestore<bool> PPDir(ParsingIfOrElifDirective, true); ++NumElse; // #elif directive in a non-skipping conditional... start skipping. diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index 7b8871576a6..20e5dd986f3 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -964,6 +964,12 @@ static bool EvaluateHasIncludeCommon(Token &Tok, // that location. If not, use the end of this location instead. SourceLocation LParenLoc = Tok.getLocation(); + // These expressions are only allowed within a preprocessor directive. + if (!PP.isParsingIfOrElifDirective()) { + PP.Diag(LParenLoc, diag::err_pp_directive_required) << II->getName(); + return false; + } + // Get '('. PP.LexNonComment(Tok); diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index 9ce4874f63f..ccb2df0602a 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -69,7 +69,8 @@ Preprocessor::Preprocessor(IntrusiveRefCntPtr<PreprocessorOptions> PPOpts, CodeCompletionFile(0), CodeCompletionOffset(0), CodeCompletionReached(0), SkipMainFilePreamble(0, true), CurPPLexer(0), CurDirLookup(0), CurLexerKind(CLK_Lexer), Callbacks(0), Listener(0), - MacroArgCache(0), Record(0), MIChainHead(0), MICache(0) + MacroArgCache(0), Record(0), MIChainHead(0), MICache(0), + ParsingIfOrElifDirective(false) { OwnsHeaderSearch = OwnsHeaders; |