diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index ece019c3a790..759fb16d1a76 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -1511,7 +1511,8 @@ static IndirectFieldDecl *FindIndirectFieldDesignator(FieldDecl *AnonField, IdentifierInfo *FieldName) { assert(AnonField->isAnonymousStructOrUnion()); Decl *NextDecl = AnonField->getNextDeclInContext(); - while (IndirectFieldDecl *IF = dyn_cast(NextDecl)) { + IndirectFieldDecl *IF = NULL; + while (NextDecl && (IF = dyn_cast(NextDecl))) { if (FieldName && FieldName == IF->getAnonField()->getIdentifier()) return IF; NextDecl = NextDecl->getNextDeclInContext(); diff --git a/clang/test/Sema/init.c b/clang/test/Sema/init.c index 2527e14fcbe9..4dcfafa4792b 100644 --- a/clang/test/Sema/init.c +++ b/clang/test/Sema/init.c @@ -18,10 +18,19 @@ extern int x; void *g = &x; int *h = &x; +struct union_crash +{ + union + { + }; +}; + int test() { -int a[10]; -int b[10] = a; // expected-error {{array initializer must be an initializer list}} -int +; // expected-error {{expected identifier or '('}} + int a[10]; + int b[10] = a; // expected-error {{array initializer must be an initializer list}} + int +; // expected-error {{expected identifier or '('}} + + struct union_crash u = { .d = 1 }; // expected-error {{field designator 'd' does not refer to any field in type 'struct union_crash'}} }