summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2015-03-29 19:05:27 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2015-03-29 19:05:27 +0000
commit0a126adc68541f8f3db60fa1ede1df200486b66a (patch)
tree6130771a6583533b76f25d1accf6139fe386f2c2
parent851f310cec3376982097f2ff69b6d8d5d00af785 (diff)
downloadbcm5719-llvm-0a126adc68541f8f3db60fa1ede1df200486b66a.tar.gz
bcm5719-llvm-0a126adc68541f8f3db60fa1ede1df200486b66a.zip
[lex] Provide a valid token when __has_include is found outside of a pp directive
ExpandBuiltinMacro would strip the identifier and downstream users crash when they encounter an identifier token with nullptr identifier info. Found by afl-fuzz. llvm-svn: 233497
-rw-r--r--clang/lib/Lex/PPMacroExpansion.cpp3
-rw-r--r--clang/test/SemaCXX/typo-correction.cpp6
2 files changed, 9 insertions, 0 deletions
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp
index f2baddd0b83..3ceba05401a 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -1073,6 +1073,9 @@ static bool EvaluateHasIncludeCommon(Token &Tok,
// These expressions are only allowed within a preprocessor directive.
if (!PP.isParsingIfOrElifDirective()) {
PP.Diag(LParenLoc, diag::err_pp_directive_required) << II->getName();
+ // Return a valid identifier token.
+ assert(Tok.is(tok::identifier));
+ Tok.setIdentifierInfo(II);
return false;
}
diff --git a/clang/test/SemaCXX/typo-correction.cpp b/clang/test/SemaCXX/typo-correction.cpp
index 324900150c7..174b1403e2d 100644
--- a/clang/test/SemaCXX/typo-correction.cpp
+++ b/clang/test/SemaCXX/typo-correction.cpp
@@ -634,3 +634,9 @@ namespace testArraySubscriptIndex {
}
};
}
+
+namespace crash_has_include {
+int has_include(int); // expected-note {{'has_include' declared here}}
+// expected-error@+1 {{__has_include must be used within a preprocessing directive}}
+int foo = __has_include(42); // expected-error {{use of undeclared identifier '__has_include'; did you mean 'has_include'?}}
+}
OpenPOWER on IntegriCloud