]> granicus.if.org Git - clang/commitdiff
Fixed processing of GNU extensions to C99 designated initializers
authorAlexey Bataev <a.bataev@hotmail.com>
Mon, 25 Jan 2016 05:14:03 +0000 (05:14 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Mon, 25 Jan 2016 05:14:03 +0000 (05:14 +0000)
Clang did not handles correctly inner parts of arrays/structures initializers in GNU extensions to C99 designated initializers.

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

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

index c3a89463dc69ec2b1690fc32fbf741f4368da57a..c60ea865aa9b5444b0b043cb977da3280c41f072 100644 (file)
@@ -2276,7 +2276,7 @@ InitListChecker::CheckDesignatedInitializer(const InitializedEntity &Entity,
       if (CheckDesignatedInitializer(MemberEntity, IList, DIE, DesigIdx + 1,
                                      FieldType, nullptr, nullptr, Index,
                                      StructuredList, newStructuredIndex,
-                                     true, false))
+                                     FinishSubobjectInit, false))
         return true;
     }
 
@@ -2467,11 +2467,11 @@ InitListChecker::CheckDesignatedInitializer(const InitializedEntity &Entity,
     Index = OldIndex;
 
     ElementEntity.setElementIndex(ElementIndex);
-    if (CheckDesignatedInitializer(ElementEntity, IList, DIE, DesigIdx + 1,
-                                   ElementType, nullptr, nullptr, Index,
-                                   StructuredList, ElementIndex,
-                                   (DesignatedStartIndex == DesignatedEndIndex),
-                                   false))
+    if (CheckDesignatedInitializer(
+            ElementEntity, IList, DIE, DesigIdx + 1, ElementType, nullptr,
+            nullptr, Index, StructuredList, ElementIndex,
+            FinishSubobjectInit && (DesignatedStartIndex == DesignatedEndIndex),
+            false))
       return true;
 
     // Move to the next index in the array that we'll be initializing.
index a2b492013d4909342667abd5f5ced625789ae5f9..5d086723cc0e1d0a9ab145d7d3f8e96c32ae24cf 100644 (file)
@@ -1,5 +1,16 @@
 // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck %s
 
+struct I { int k[3]; };
+struct M { struct I o[2]; };
+struct M v1[1] = { [0].o[0 ... 1].k[0 ... 1] = 4, 5 };
+unsigned v2[2][3] = {[0 ... 1][0 ... 1] = 2222, 3333};
+
+// CHECK-DAG: %struct.M = type { [2 x %struct.I] }
+// CHECK-DAG: %struct.I = type { [3 x i32] }
+
+// CHECK: [1 x %struct.M] [%struct.M { [2 x %struct.I] [%struct.I { [3 x i32] [i32 4, i32 4, i32 0] }, %struct.I { [3 x i32] [i32 4, i32 4, i32 5] }] }],
+// CHECK: [2 x [3 x i32]] {{[[][[]}}3 x i32] [i32 2222, i32 2222, i32 0], [3 x i32] [i32 2222, i32 2222, i32 3333]],
+
 void f1() {
   // Scalars in braces.
   int a = { 1 };