]> granicus.if.org Git - clang/commitdiff
Fix a crash on test/Sema/invalid-decl.c
authorChris Lattner <sabre@nondot.org>
Fri, 19 Oct 2007 20:10:30 +0000 (20:10 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 19 Oct 2007 20:10:30 +0000 (20:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43188 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/SemaDecl.cpp
test/Sema/invalid-decl.c [new file with mode: 0644]

index ee3cc7a88c2e6e3bdb67bf9540d10a8e24b51c83..db10de2a44f69aa8ea7087ec9a1114445bbe4893 100644 (file)
@@ -635,8 +635,14 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) {
 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) {
diff --git a/test/Sema/invalid-decl.c b/test/Sema/invalid-decl.c
new file mode 100644 (file)
index 0000000..bd9302b
--- /dev/null
@@ -0,0 +1,7 @@
+
+void test() {
+    char = 4;  // expected-error {{expected identifier}} expected-error{{declarator requires an identifier}}
+
+}
+
+