[cfe-commits] r43188 - in /cfe/trunk: Sema/SemaDecl.cpp test/Sema/invalid-decl.c

Chris Lattner sabre at nondot.org
Fri Oct 19 13:10:30 PDT 2007


Author: lattner
Date: Fri Oct 19 15:10:30 2007
New Revision: 43188

URL: http://llvm.org/viewvc/llvm-project?rev=43188&view=rev
Log:
Fix a crash on test/Sema/invalid-decl.c  


Added:
    cfe/trunk/test/Sema/invalid-decl.c
Modified:
    cfe/trunk/Sema/SemaDecl.cpp

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=43188&r1=43187&r2=43188&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Fri Oct 19 15:10:30 2007
@@ -635,8 +635,14 @@
 void Sema::AddInitializerToDecl(DeclTy *dcl, ExprTy *init) {
   Decl *RealDecl = static_cast<Decl *>(dcl);
   Expr *Init = static_cast<Expr *>(init);
+  assert(Init && "missing initializer");
   
-  assert((RealDecl && Init) && "missing decl or initializer");
+  // If there is no declaration, there was an error parsing it.  Just ignore
+  // the initializer.
+  if (RealDecl == 0) {
+    delete Init;
+    return;
+  }
   
   VarDecl *VDecl = dyn_cast<VarDecl>(RealDecl);
   if (!VDecl) {

Added: cfe/trunk/test/Sema/invalid-decl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/invalid-decl.c?rev=43188&view=auto

==============================================================================
--- cfe/trunk/test/Sema/invalid-decl.c (added)
+++ cfe/trunk/test/Sema/invalid-decl.c Fri Oct 19 15:10:30 2007
@@ -0,0 +1,7 @@
+
+void test() {
+    char = 4;  // expected-error {{expected identifier}} expected-error{{declarator requires an identifier}}
+
+}
+
+





More information about the cfe-commits mailing list