summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex/PPDirectives.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-05-25 17:16:10 +0000
committerChris Lattner <sabre@nondot.org>2009-05-25 17:16:10 +0000
commit83bd8281e556a42b47e5b136691128236d8d1e2f (patch)
tree649e7479327951e6432d72e3ea828866b90e0c8a /clang/lib/Lex/PPDirectives.cpp
parentbe31b7b5346eb07c29c9ab68bc0743cc7d2c3d0e (diff)
downloadbcm5719-llvm-83bd8281e556a42b47e5b136691128236d8d1e2f.tar.gz
bcm5719-llvm-83bd8281e556a42b47e5b136691128236d8d1e2f.zip
Fix a couple of bugs:
1. When we accept "#garbage" in asm-with-cpp mode, change the token kind of the # to unknown so that the preprocessor won't try to process it as a real #. This fixes a crash on the attached example 2. Fix macro definition extents processing to handle #foo at the end of a macro to say the definition ends with the foo, not the #. This is a follow-on fix to r72283, and rdar://6916026 llvm-svn: 72388
Diffstat (limited to 'clang/lib/Lex/PPDirectives.cpp')
-rw-r--r--clang/lib/Lex/PPDirectives.cpp45
1 files changed, 27 insertions, 18 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index d7b8fc7fd82..af59ded2754 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1359,15 +1359,15 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) {
}
} else {
- // Otherwise, read the body of a function-like macro. This has to validate
- // the # (stringize) operator.
+ // Otherwise, read the body of a function-like macro. While we are at it,
+ // check C99 6.10.3.2p1: ensure that # operators are followed by macro
+ // parameters in function-like macro expansions.
while (Tok.isNot(tok::eom)) {
LastTok = Tok;
- MI->AddTokenToBody(Tok);
- // Check C99 6.10.3.2p1: ensure that # operators are followed by macro
- // parameters in function-like macro expansions.
if (Tok.isNot(tok::hash)) {
+ MI->AddTokenToBody(Tok);
+
// Get the next token of the macro.
LexUnexpandedToken(Tok);
continue;
@@ -1376,22 +1376,31 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) {
// Get the next token of the macro.
LexUnexpandedToken(Tok);
- // Check for a valid macro arg identifier, unless this is a .S file in
- // which case it is still added to the body.
- if ((!Tok.getIdentifierInfo() ||
- MI->getArgumentNum(Tok.getIdentifierInfo()) == -1) &&
- !getLangOptions().AsmPreprocessor) {
- Diag(Tok, diag::err_pp_stringize_not_parameter);
- ReleaseMacroInfo(MI);
-
- // Disable __VA_ARGS__ again.
- Ident__VA_ARGS__->setIsPoisoned(true);
- return;
+ // Check for a valid macro arg identifier.
+ if (Tok.getIdentifierInfo() == 0 ||
+ MI->getArgumentNum(Tok.getIdentifierInfo()) == -1) {
+
+ // If this is assembler-with-cpp mode, we accept random gibberish after
+ // the '#' because '#' is often a comment character. However, change
+ // the kind of the token to tok::unknown so that the preprocessor isn't
+ // confused.
+ if (getLangOptions().AsmPreprocessor && Tok.isNot(tok::eom)) {
+ LastTok.setKind(tok::unknown);
+ } else {
+ Diag(Tok, diag::err_pp_stringize_not_parameter);
+ ReleaseMacroInfo(MI);
+
+ // Disable __VA_ARGS__ again.
+ Ident__VA_ARGS__->setIsPoisoned(true);
+ return;
+ }
}
- // Things look ok, add the param name token to the macro.
+ // Things look ok, add the '#' and param name tokens to the macro.
+ MI->AddTokenToBody(LastTok);
MI->AddTokenToBody(Tok);
-
+ LastTok = Tok;
+
// Get the next token of the macro.
LexUnexpandedToken(Tok);
}
OpenPOWER on IntegriCloud