]> granicus.if.org Git - clang/commitdiff
Fix CheckEndOfDirective to diagnose lines that contain macros that expand to
authorChris Lattner <sabre@nondot.org>
Sat, 16 Feb 2008 01:20:36 +0000 (01:20 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 16 Feb 2008 01:20:36 +0000 (01:20 +0000)
zero tokens.  This fixes PR2045, thanks to Neil for finding another
incredibly subtle corner case :)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47203 91177308-0d34-0410-b5e6-96231b3b80d8

Lex/Preprocessor.cpp
Sema/SemaDecl.cpp
test/Preprocessor/undef-error.c [new file with mode: 0644]

index a291fe35dfbabf74afc3c98d0ce9344c05ea9109..7bd359ae18d6778ddc7c47561a807937929dd9cc 100644 (file)
@@ -1498,11 +1498,14 @@ void Preprocessor::ReadMacroName(Token &MacroNameTok, char isDefineUndef) {
 /// 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);
index 2f866c0497520a7bb632125568919f20895e95fe..61de36faf69d5547691b405a1db928bd2102e520 100644 (file)
@@ -1032,8 +1032,7 @@ Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) {
     }
   }
   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.
diff --git a/test/Preprocessor/undef-error.c b/test/Preprocessor/undef-error.c
new file mode 100644 (file)
index 0000000..af9f516
--- /dev/null
@@ -0,0 +1,5 @@
+// RUN: not clang %s -pedantic-errors -E
+// PR2045
+
+#define b
+#undef a b