summaryrefslogtreecommitdiffstats
path: root/clang/test/CodeGen/partial-reinitialization2.c
diff options
context:
space:
mode:
authorYunzhong Gao <Yunzhong_Gao@playstation.sony.com>2015-06-10 00:27:52 +0000
committerYunzhong Gao <Yunzhong_Gao@playstation.sony.com>2015-06-10 00:27:52 +0000
commitcb77930d6b20e53c735233eecf4572a1c30eb0c0 (patch)
tree74f8f3c0612aee5391a6cb5bbb5eb01c0a6d5be8 /clang/test/CodeGen/partial-reinitialization2.c
parent7912d9b8999266e55ff40e15d37fa458e66f436c (diff)
downloadbcm5719-llvm-cb77930d6b20e53c735233eecf4572a1c30eb0c0.tar.gz
bcm5719-llvm-cb77930d6b20e53c735233eecf4572a1c30eb0c0.zip
Implementing C99 partial re-initialization behavior (DR-253)
Based on previous discussion on the mailing list, clang currently lacks support for C99 partial re-initialization behavior: Reference: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2013-April/029188.html Reference: http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_253.htm This patch attempts to fix this problem. Given the following code snippet, struct P1 { char x[6]; }; struct LP1 { struct P1 p1; }; struct LP1 l = { .p1 = { "foo" }, .p1.x[2] = 'x' }; // this example is adapted from the example for "struct fred x[]" in DR-253; // currently clang produces in l: { "\0\0x" }, // whereas gcc 4.8 produces { "fox" }; // with this fix, clang will also produce: { "fox" }; Differential Review: http://reviews.llvm.org/D5789 llvm-svn: 239446
Diffstat (limited to 'clang/test/CodeGen/partial-reinitialization2.c')
-rw-r--r--clang/test/CodeGen/partial-reinitialization2.c108
1 files changed, 108 insertions, 0 deletions
diff --git a/clang/test/CodeGen/partial-reinitialization2.c b/clang/test/CodeGen/partial-reinitialization2.c
new file mode 100644
index 00000000000..f8885623713
--- /dev/null
+++ b/clang/test/CodeGen/partial-reinitialization2.c
@@ -0,0 +1,108 @@
+// RUN: %clang_cc1 %s -triple x86_64-unknown-unknown -emit-llvm -o - | FileCheck %s
+
+struct P1 { char x[6]; } g1 = { "foo" };
+struct LP1 { struct P1 p1; };
+
+struct P2 { int a, b, c; } g2 = { 1, 2, 3 };
+struct LP2 { struct P2 p2; };
+struct LP2P2 { struct P2 p1, p2; };
+union UP2 { struct P2 p2; };
+
+struct LP3 { struct P1 p1[2]; } g3 = { { "dog" }, { "cat" } };
+struct LLP3 { struct LP3 l3; };
+union ULP3 { struct LP3 l3; };
+
+// CHECK-LABEL: test1
+void test1(void)
+{
+ // CHECK: call void @llvm.memcpy{{.*}}%struct.P1, %struct.P1* @g1{{.*}}i64 6, i32 {{[0-9]}}, i1 false)
+ // CHECK: store i8 120, i8* %arrayinit
+
+ struct LP1 l = { .p1 = g1, .p1.x[2] = 'x' };
+}
+
+// CHECK-LABEL: test2
+void test2(void)
+{
+ // CHECK: call void @llvm.memcpy{{.*}}%struct.P1, %struct.P1* @g1{{.*}}i64 6, i32 {{[0-9]}}, i1 false)
+ // CHECK: store i8 114, i8* %arrayinit
+
+ struct LP1 l = { .p1 = g1, .p1.x[1] = 'r' };
+}
+
+// CHECK-LABEL: test3
+void test3(void)
+{
+ // CHECK: call void @llvm.memcpy{{.*}}%struct.P2* @g2{{.*}}i64 12, i32 {{[0-9]}}, i1 false)
+ // CHECK: store i32 10, i32* %b
+
+ struct LP2 l = { .p2 = g2, .p2.b = 10 };
+}
+
+// CHECK-LABEL: get235
+struct P2 get235()
+{
+ struct P2 p = { 2, 3, 5 };
+ return p;
+}
+
+// CHECK-LABEL: get456789
+struct LP2P2 get456789()
+{
+ struct LP2P2 l = { { 4, 5, 6 }, { 7, 8, 9 } };
+ return l;
+}
+
+// CHECK-LABEL: get123
+union UP2 get123()
+{
+ union UP2 u = { { 1, 2, 3 } };
+ return u;
+}
+
+// CHECK-LABEL: test4
+void test4(void)
+{
+ // CHECK: [[CALL:%[a-z0-9]+]] = call {{.*}}@get123()
+ // CHECK: store{{.*}}[[CALL]], {{.*}}[[TMP0:%[a-z0-9]+]]
+ // CHECK: [[TMP1:%[a-z0-9]+]] = bitcast {{.*}}[[TMP0]]
+ // CHECK: call void @llvm.memcpy{{.*}}[[TMP1]], i64 12, i32 {{[0-9]}}, i1 false)
+ // CHECK: store i32 100, i32* %a
+
+ struct LUP2 { union UP2 up; } var = { get123(), .up.p2.a = 100 };
+}
+
+// CHECK-LABEL: test5
+void test5(void)
+{
+ // .l3 = g3
+ // CHECK: call void @llvm.memcpy{{.*}}%struct.LP3, %struct.LP3* @g3{{.*}}i64 12, i32 {{[0-9]}}, i1 false)
+
+ // .l3.p1 = { [0] = g1 } implicitly sets [1] to zero
+ // CHECK: call void @llvm.memcpy{{.*}}%struct.P1, %struct.P1* @g1{{.*}}i64 6, i32 {{[0-9]}}, i1 false)
+ // CHECK: getelementptr{{.*}}%struct.P1, %struct.P1*{{.*}}i64 1
+ // CHECK: call void @llvm.memset{{.*}}i8 0, i64 6, i32 {{[0-9]}}, i1 false)
+
+ // .l3.p1[1].x[1] = 'x'
+ // CHECK: store i8 120, i8* %arrayinit
+
+ struct LLP3 var = { .l3 = g3, .l3.p1 = { [0] = g1 }, .l3.p1[1].x[1] = 'x' };
+}
+
+// CHECK-LABEL: test6
+void test6(void)
+{
+ // CHECK: [[LP:%[a-z0-9]+]] = getelementptr{{.*}}%struct.LLP2P2, %struct.LLP2P2*{{.*}}, i32 0, i32 0
+ // CHECK: call {{.*}}get456789(%struct.LP2P2* {{.*}}[[LP]])
+
+ // CHECK: [[CALL:%[a-z0-9]+]] = call {{.*}}@get235()
+ // CHECK: store{{.*}}[[CALL]], {{.*}}[[TMP0:%[a-z0-9]+]]
+ // CHECK: [[TMP1:%[a-z0-9]+]] = bitcast {{.*}}[[TMP0]]
+ // CHECK: call void @llvm.memcpy{{.*}}[[TMP1]], i64 12, i32 {{[0-9]}}, i1 false)
+
+ // CHECK: store i32 10, i32* %b
+
+ struct LLP2P2 { struct LP2P2 lp; } var = { get456789(),
+ .lp.p1 = get235(),
+ .lp.p1.b = 10 };
+}
OpenPOWER on IntegriCloud