r233497 - [lex] Provide a valid token when __has_include is found outside of a pp directive
Benjamin Kramer
benny.kra at googlemail.com
Sun Mar 29 12:05:27 PDT 2015
Author: d0k
Date: Sun Mar 29 14:05:27 2015
New Revision: 233497
URL: http://llvm.org/viewvc/llvm-project?rev=233497&view=rev
Log:
[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.
Modified:
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
cfe/trunk/test/SemaCXX/typo-correction.cpp
Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=233497&r1=233496&r2=233497&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Sun Mar 29 14:05:27 2015
@@ -1073,6 +1073,9 @@ static bool EvaluateHasIncludeCommon(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;
}
Modified: cfe/trunk/test/SemaCXX/typo-correction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typo-correction.cpp?rev=233497&r1=233496&r2=233497&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/typo-correction.cpp (original)
+++ cfe/trunk/test/SemaCXX/typo-correction.cpp Sun Mar 29 14:05:27 2015
@@ -634,3 +634,9 @@ namespace testArraySubscriptIndex {
}
};
}
+
+namespace crash_has_include {
+int has_include(int); // expected-note {{'has_include' declared here}}
+// expected-error at +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'?}}
+}
More information about the cfe-commits
mailing list