]> granicus.if.org Git - clang/commitdiff
implement a tiny amount of codegen support for gnu array range
authorChris Lattner <sabre@nondot.org>
Sat, 19 Feb 2011 22:28:58 +0000 (22:28 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 19 Feb 2011 22:28:58 +0000 (22:28 +0000)
designators: allowing codegen when the element initializer is a
constant or something else without a side effect.  This unblocks
enough to let process.c in the linux kernel build, PR9257.

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

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

index b0749484f5d885e3c99cb660697b4887e22758c3..b9a6a5713b8bb673317c005025bd570d155f3eac 100644 (file)
@@ -1593,14 +1593,19 @@ InitListChecker::CheckDesignatedInitializer(const InitializedEntity &Entity,
   } else {
     assert(D->isArrayRangeDesignator() && "Need array-range designator");
 
-
     DesignatedStartIndex =
       DIE->getArrayRangeStart(*D)->EvaluateAsInt(SemaRef.Context);
     DesignatedEndIndex =
       DIE->getArrayRangeEnd(*D)->EvaluateAsInt(SemaRef.Context);
     IndexExpr = DIE->getArrayRangeEnd(*D);
 
-    if (DesignatedStartIndex.getZExtValue() !=DesignatedEndIndex.getZExtValue())
+    // Codegen can't handle evaluating array range designators that have side
+    // effects, because we replicate the AST value for each initialized element.
+    // As such, set the sawArrayRangeDesignator() bit if we initialize multiple
+    // elements with something that has a side effect, so codegen can emit an
+    // "error unsupported" error instead of miscompiling the app.
+    if (DesignatedStartIndex.getZExtValue()!=DesignatedEndIndex.getZExtValue()&&
+        DIE->getInit()->HasSideEffects(SemaRef.Context))
       FullyStructuredList->sawArrayRangeDesignator();
   }
 
index ccb04f343c6071aad180cea1af6def74f4a49815..0f94729a949eca245b2cd0911d94248da4361741 100644 (file)
@@ -100,3 +100,18 @@ int test10(int X) {
   // CHECK-NOT: store i32 0
   // CHECK: call void @bar
 }
+
+
+// PR9257
+struct test11S {
+  int A[10];
+};
+void test11(struct test11S *P) {
+  *P = (struct test11S) { .A = { [0 ... 3] = 4 } };
+  // CHECK: @test11
+  // CHECK: store i32 4
+  // CHECK: store i32 4
+  // CHECK: store i32 4
+  // CHECK: store i32 4
+  // CHECK: ret void
+}