]> granicus.if.org Git - clang/commitdiff
Attempting to initialize a union member that does not exist no longer crashes.
authorAaron Ballman <aaron@aaronballman.com>
Thu, 9 Feb 2012 03:29:06 +0000 (03:29 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Thu, 9 Feb 2012 03:29:06 +0000 (03:29 +0000)
Patch by Remi Gacogne

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

lib/Sema/SemaInit.cpp
test/Sema/init.c

index ece019c3a790d0ff2163d02ab83466c2017901c9..759fb16d1a7686f6c5f67177c796891b4e9e6e2d 100644 (file)
@@ -1511,7 +1511,8 @@ static IndirectFieldDecl *FindIndirectFieldDesignator(FieldDecl *AnonField,
                                                  IdentifierInfo *FieldName) {
   assert(AnonField->isAnonymousStructOrUnion());
   Decl *NextDecl = AnonField->getNextDeclInContext();
-  while (IndirectFieldDecl *IF = dyn_cast<IndirectFieldDecl>(NextDecl)) {
+  IndirectFieldDecl *IF = NULL;
+  while (NextDecl && (IF = dyn_cast<IndirectFieldDecl>(NextDecl))) {
     if (FieldName && FieldName == IF->getAnonField()->getIdentifier())
       return IF;
     NextDecl = NextDecl->getNextDeclInContext();
index 2527e14fcbe9ed85d7f2c26da9f6e0de46567046..4dcfafa4792bb925dc35b0135384b9ce4b804ce1 100644 (file)
@@ -18,10 +18,19 @@ extern int x;
 void *g = &x;
 int *h = &x;
 
+struct union_crash\r
+{\r
+    union\r
+    {\r
+    };\r
+};\r
+
 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'}}
 }