From 9a11b9abb9daa9d7c02e13bb4d62caaadb22477d Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 19 Oct 2007 20:10:30 +0000 Subject: [PATCH] Fix a crash on test/Sema/invalid-decl.c git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43188 91177308-0d34-0410-b5e6-96231b3b80d8 --- Sema/SemaDecl.cpp | 8 +++++++- test/Sema/invalid-decl.c | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/Sema/invalid-decl.c diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index ee3cc7a88c..db10de2a44 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -635,8 +635,14 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) { void Sema::AddInitializerToDecl(DeclTy *dcl, ExprTy *init) { Decl *RealDecl = static_cast(dcl); Expr *Init = static_cast(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(RealDecl); if (!VDecl) { diff --git a/test/Sema/invalid-decl.c b/test/Sema/invalid-decl.c new file mode 100644 index 0000000000..bd9302b206 --- /dev/null +++ b/test/Sema/invalid-decl.c @@ -0,0 +1,7 @@ + +void test() { + char = 4; // expected-error {{expected identifier}} expected-error{{declarator requires an identifier}} + +} + + -- 2.50.1