summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex/PPMacroExpansion.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-12-15 09:03:58 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-12-15 09:03:58 +0000
commitd616362fe3dc7074945fd476ba8c43fa82524f87 (patch)
tree04bf19d9d90684a793c904c010eaf5c9fc310ff5 /clang/lib/Lex/PPMacroExpansion.cpp
parent418ad3ff107dfde7f6d7c3e87f810fbbb8515ed4 (diff)
downloadbcm5719-llvm-d616362fe3dc7074945fd476ba8c43fa82524f87.tar.gz
bcm5719-llvm-d616362fe3dc7074945fd476ba8c43fa82524f87.zip
Preprocessor: Recover instead of mutating a token in ExpandBuiltinMacro
We would CreateString on arbitrary garbage instead of just skipping to the end of the builtin macro. Eventually, this would cause us to crash because we would end up replacing the contents of a character token with a numeric literal. This fixes PR21825. llvm-svn: 224238
Diffstat (limited to 'clang/lib/Lex/PPMacroExpansion.cpp')
-rw-r--r--clang/lib/Lex/PPMacroExpansion.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp
index d9a7f39913a..cd05d06633f 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -1415,6 +1415,10 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
if (IsScopeValid && Tok.is(tok::r_paren))
IsValid = true;
}
+ // Eat tokens until ')'.
+ while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::eod) &&
+ Tok.isNot(tok::eof))
+ LexUnexpandedToken(Tok);
}
int Value = 0;
@@ -1441,9 +1445,10 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
Value = HasFeature(*this, FeatureII);
}
+ if (!IsValid)
+ return;
OS << Value;
- if (IsValid)
- Tok.setKind(tok::numeric_constant);
+ Tok.setKind(tok::numeric_constant);
} else if (II == Ident__has_include ||
II == Ident__has_include_next) {
// The argument to these two builtins should be a parenthesized
@@ -1507,9 +1512,10 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
WarningName.substr(2), Diags);
} while (false);
+ if (!IsValid)
+ return;
OS << (int)Value;
- if (IsValid)
- Tok.setKind(tok::numeric_constant);
+ Tok.setKind(tok::numeric_constant);
} else if (II == Ident__building_module) {
// The argument to this builtin should be an identifier. The
// builtin evaluates to 1 when that identifier names the module we are
OpenPOWER on IntegriCloud