[cfe-commits] r47203 - in /cfe/trunk: Lex/Preprocessor.cpp Sema/SemaDecl.cpp test/Preprocessor/undef-error.c
Chris Lattner
sabre at nondot.org
Fri Feb 15 17:20:37 PST 2008
Author: lattner
Date: Fri Feb 15 19:20:36 2008
New Revision: 47203
URL: http://llvm.org/viewvc/llvm-project?rev=47203&view=rev
Log:
Fix CheckEndOfDirective to diagnose lines that contain macros that expand to
zero tokens. This fixes PR2045, thanks to Neil for finding another
incredibly subtle corner case :)
Added:
cfe/trunk/test/Preprocessor/undef-error.c
Modified:
cfe/trunk/Lex/Preprocessor.cpp
cfe/trunk/Sema/SemaDecl.cpp
Modified: cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/Preprocessor.cpp?rev=47203&r1=47202&r2=47203&view=diff
==============================================================================
--- cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/Lex/Preprocessor.cpp Fri Feb 15 19:20:36 2008
@@ -1498,11 +1498,14 @@
/// not, emit a diagnostic and consume up until the eom.
void Preprocessor::CheckEndOfDirective(const char *DirType) {
Token Tmp;
- Lex(Tmp);
+ // Lex unexpanded tokens: macros might expand to zero tokens, causing us to
+ // miss diagnosing invalid lines.
+ LexUnexpandedToken(Tmp);
+
// There should be no tokens after the directive, but we allow them as an
// extension.
while (Tmp.is(tok::comment)) // Skip comments in -C mode.
- Lex(Tmp);
+ LexUnexpandedToken(Tmp);
if (Tmp.isNot(tok::eom)) {
Diag(Tmp, diag::ext_pp_extra_tokens_at_eol, DirType);
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=47203&r1=47202&r2=47203&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Fri Feb 15 19:20:36 2008
@@ -1032,8 +1032,7 @@
}
}
Decl *decl = static_cast<Decl*>(ActOnDeclarator(GlobalScope, D, 0));
- FunctionDecl *FD = dyn_cast<FunctionDecl>(decl);
- assert(FD != 0 && "ActOnDeclarator() didn't return a FunctionDecl");
+ FunctionDecl *FD = cast<FunctionDecl>(decl);
CurFunctionDecl = FD;
// Create Decl objects for each parameter, adding them to the FunctionDecl.
Added: cfe/trunk/test/Preprocessor/undef-error.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/undef-error.c?rev=47203&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/undef-error.c (added)
+++ cfe/trunk/test/Preprocessor/undef-error.c Fri Feb 15 19:20:36 2008
@@ -0,0 +1,5 @@
+// RUN: not clang %s -pedantic-errors -E
+// PR2045
+
+#define b
+#undef a b
More information about the cfe-commits
mailing list