diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Analysis/designated-initializer.c | 41 | ||||
-rw-r--r-- | clang/test/CodeGen/partial-reinitialization1.c | 74 | ||||
-rw-r--r-- | clang/test/CodeGen/partial-reinitialization2.c | 108 | ||||
-rw-r--r-- | clang/test/PCH/designated-init.c.h | 22 | ||||
-rw-r--r-- | clang/test/Sema/designated-initializers.c | 24 | ||||
-rw-r--r-- | clang/test/SemaCXX/decltype.cpp | 25 |
6 files changed, 287 insertions, 7 deletions
diff --git a/clang/test/Analysis/designated-initializer.c b/clang/test/Analysis/designated-initializer.c new file mode 100644 index 00000000000..b601f872571 --- /dev/null +++ b/clang/test/Analysis/designated-initializer.c @@ -0,0 +1,41 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=debug.DumpCFG %s 2>&1 \ +// RUN: | FileCheck %s + +struct Q { int a, b, c; }; +union UQ { struct Q q; }; +union UQ getUQ() { + union UQ u = { { 1, 2, 3 } }; + return u; +} + +void test() { + struct LUQ { union UQ uq; } var = { getUQ(), .uq.q.a = 100 }; + struct Q s[] = { + [0] = (struct Q){1, 2}, + [0].c = 3 + }; +} + +// CHECK: void test() +// CHECK: [B1] +// CHECK: 1: getUQ +// CHECK: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, union UQ (*)()) +// CHECK: 3: [B1.2]() +// CHECK: 4: 100 +// CHECK: 5: /*no init*/ +// CHECK: 6: /*no init*/ +// CHECK: 7: {[B1.4], [B1.5], [B1.6]} +// CHECK: 8: {[B1.7]} +// CHECK: 9: {/*base*/[B1.3], /*updater*/[B1.8]} +// CHECK: 10: {[B1.3], .uq.q.a = [B1.4]} +// CHECK: 11: struct LUQ var = {getUQ(), .uq.q.a = 100}; +// CHECK: 12: 1 +// CHECK: 13: 2 +// CHECK: 14: /*implicit*/(int)0 +// CHECK: 15: {[B1.12], [B1.13]} +// CHECK: 18: /*no init*/ +// CHECK: 19: /*no init*/ +// CHECK: 20: 3 +// CHECK: 21: {[B1.18], [B1.19], [B1.20]} +// CHECK: 22: {/*base*/[B1.17], /*updater*/[B1.21]} +// CHECK: 24: struct Q s[] = {[0] = (struct Q){1, 2}, [0].c = 3}; diff --git a/clang/test/CodeGen/partial-reinitialization1.c b/clang/test/CodeGen/partial-reinitialization1.c new file mode 100644 index 00000000000..6a764b7fb02 --- /dev/null +++ b/clang/test/CodeGen/partial-reinitialization1.c @@ -0,0 +1,74 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -emit-llvm -o - | FileCheck %s + +struct P1 { + struct Q1 { + char a[6]; + char b[6]; + } q; +}; + +// CHECK: { [6 x i8] c"foo\00\00\00", [6 x i8] c"\00x\00\00\00\00" } +struct P1 l1 = { + (struct Q1){ "foo", "bar" }, + .q.b = { "boo" }, + .q.b = { [1] = 'x' } +}; + +// CHECK: { [6 x i8] c"foo\00\00\00", [6 x i8] c"bxo\00\00\00" } +struct P1 l1a = { + (struct Q1){ "foo", "bar" }, + .q.b = { "boo" }, + .q.b[1] = 'x' +}; + + +struct P2 { char x[6]; }; + +// CHECK: { [6 x i8] c"n\00\00\00\00\00" } +struct P2 l2 = { + .x = { [1] = 'o' }, + .x = { [0] = 'n' } +}; + +struct P3 { + struct Q3 { + struct R1 { + int a, b, c; + } r1; + + struct R2 { + int d, e, f; + } r2; + } q; +}; + +// CHECK: @l3 = global %struct.P3 { %struct.Q3 { %struct.R1 { i32 1, i32 2, i32 3 }, %struct.R2 { i32 0, i32 10, i32 0 } } } +struct P3 l3 = { + (struct Q3){ { 1, 2, 3 }, { 4, 5, 6 } }, + .q.r2 = { 7, 8, 9 }, + .q.r2 = { .e = 10 } +}; + +// This bit is taken from Sema/wchar.c so we can avoid the wchar.h include. +typedef __WCHAR_TYPE__ wchar_t; + +struct P4 { + wchar_t x[6]; +}; + +// CHECK: { [6 x i32] [i32 102, i32 111, i32 120, i32 0, i32 0, i32 0] } +struct P4 l4 = { { L"foo" }, .x[2] = L'x' }; + +struct P5 { + int x; + struct Q5 { + int a, b, c; + } q; + int y; +}; + +// A three-pass test +// CHECK: @l5 = global %struct.P5 { i32 1, %struct.Q5 { i32 6, i32 9, i32 8 }, i32 5 } +struct P5 l5 = { 1, { 2, 3, 4 }, 5, + .q = { 6, 7, 8 }, + .q.b = 9 }; 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 }; +} diff --git a/clang/test/PCH/designated-init.c.h b/clang/test/PCH/designated-init.c.h index 63b1f790ea4..18216279c2e 100644 --- a/clang/test/PCH/designated-init.c.h +++ b/clang/test/PCH/designated-init.c.h @@ -40,3 +40,25 @@ static void *FooTable[256] = { }, } }; + +struct P1 { + struct Q1 { + char a[6]; + char b[6]; + } q; +}; + +struct P1 l1 = { + (struct Q1){ "foo", "bar" }, + .q.b = { "boo" }, + .q.b = { [1] = 'x' } +}; + +extern struct Q1 *foo(); +static struct P1 test_foo() { + struct P1 l = { *foo(), + .q.b = { "boo" }, + .q.b = { [1] = 'x' } + }; + return l; +} diff --git a/clang/test/Sema/designated-initializers.c b/clang/test/Sema/designated-initializers.c index 6630da67c5b..a4582deb171 100644 --- a/clang/test/Sema/designated-initializers.c +++ b/clang/test/Sema/designated-initializers.c @@ -45,8 +45,8 @@ struct point array[10] = { struct point array2[10] = { [10].x = 2.0, // expected-error{{array designator index (10) exceeds array bounds (10)}} - [4 ... 5].y = 2.0, - [4 ... 6] = { .x = 3, .y = 4.0 } + [4 ... 5].y = 2.0, // expected-note 2 {{previous initialization is here}} + [4 ... 6] = { .x = 3, .y = 4.0 } // expected-warning 2 {{subobject initialization overrides initialization of other fields within its enclosing subobject}} }; struct point array3[10] = { @@ -129,11 +129,11 @@ int get8() { ++counter; return 8; } void test() { struct X xs[] = { - [0] = (struct X){1, 2}, // expected-note{{previous initialization is here}} + [0] = (struct X){1, 2}, // expected-note 2 {{previous initialization is here}} [0].c = 3, // expected-warning{{subobject initialization overrides initialization of other fields within its enclosing subobject}} (struct X) {4, 5, 6}, // expected-note{{previous initialization is here}} [1].b = get8(), // expected-warning{{subobject initialization overrides initialization of other fields within its enclosing subobject}} - [0].b = 8 + [0].b = 8 // expected-warning{{subobject initialization overrides initialization of other fields within its enclosing subobject}} }; } @@ -332,12 +332,22 @@ struct overwrite_string_struct { int M; } overwrite_string[] = { { { "foo" }, 1 }, // expected-note {{previous initialization is here}} - [0].L[2] = 'x' // expected-warning{{initializer overrides prior initialization of this subobject}} + [0].L[2] = 'x' // expected-warning{{subobject initialization overrides initialization of other fields}} }; struct overwrite_string_struct2 { char L[6]; int M; } overwrite_string2[] = { - { { "foo" }, 1 }, - [0].L[4] = 'x' // no-warning + { { "foo" }, 1 }, // expected-note{{previous initialization is here}} + [0].L[4] = 'x' // expected-warning{{subobject initialization overrides initialization of other fields}} }; +struct overwrite_string_struct +overwrite_string3[] = { + "foo", 1, // expected-note{{previous initialization is here}} + [0].L[4] = 'x' // expected-warning{{subobject initialization overrides initialization of other fields}} +}; +struct overwrite_string_struct +overwrite_string4[] = { + { { 'f', 'o', 'o' }, 1 }, + [0].L[4] = 'x' // no-warning +}; diff --git a/clang/test/SemaCXX/decltype.cpp b/clang/test/SemaCXX/decltype.cpp index f1900b2b830..2956f9a228e 100644 --- a/clang/test/SemaCXX/decltype.cpp +++ b/clang/test/SemaCXX/decltype.cpp @@ -76,6 +76,31 @@ namespace PR18876 { decltype(f(), 0) *e; // expected-error {{attempt to use a deleted function}} } +namespace D5789 { + struct P1 { char x[6]; } g1 = { "foo" }; + struct LP1 { struct P1 p1; }; + + // expected-warning@+3 {{subobject initialization overrides}} + // expected-note@+2 {{previous initialization}} + // expected-note@+1 {{previous definition}} + template<class T> void foo(decltype(T(LP1{ .p1 = g1, .p1.x[1] = 'x' }))) {} + + // expected-warning@+3 {{subobject initialization overrides}} + // expected-note@+2 {{previous initialization}} + template<class T> + void foo(decltype(T(LP1{ .p1 = g1, .p1.x[1] = 'r' }))) {} // okay + + // expected-warning@+3 {{subobject initialization overrides}} + // expected-note@+2 {{previous initialization}} + template<class T> + void foo(decltype(T(LP1{ .p1 = { "foo" }, .p1.x[1] = 'x'}))) {} // okay + + // expected-warning@+3 {{subobject initialization overrides}} + // expected-note@+2 {{previous initialization}} + // expected-error@+1 {{redefinition of 'foo'}} + template<class T> void foo(decltype(T(LP1{ .p1 = g1, .p1.x[1] = 'x' }))) {} +} + template<typename> class conditional { }; |