2010-04-17 04:56:35 +08:00
|
|
|
// RUN: %clang_cc1 -triple i386-unknown-unknown %s -emit-llvm -o - | FileCheck %s
|
2009-01-30 20:58:18 +08:00
|
|
|
|
2009-01-30 01:44:32 +08:00
|
|
|
struct foo {
|
|
|
|
void *a;
|
|
|
|
int b;
|
|
|
|
};
|
|
|
|
|
2011-07-12 13:53:08 +08:00
|
|
|
// CHECK: @u = global %union.anon zeroinitializer
|
2009-01-30 01:44:32 +08:00
|
|
|
union { int i; float f; } u = { };
|
|
|
|
|
2011-07-10 01:41:47 +08:00
|
|
|
// CHECK: @u2 = global { i32, [4 x i8] } { i32 0, [4 x i8] undef }
|
2010-04-17 04:56:35 +08:00
|
|
|
union { int i; double f; } u2 = { };
|
2009-03-28 07:40:29 +08:00
|
|
|
|
2011-07-12 13:53:08 +08:00
|
|
|
// CHECK: @u3 = global %union.anon.1 zeroinitializer
|
2010-04-17 05:19:39 +08:00
|
|
|
union { double f; int i; } u3 = { };
|
|
|
|
|
2010-04-17 04:56:35 +08:00
|
|
|
// CHECK: @b = global [2 x i32] [i32 0, i32 22]
|
2009-03-28 07:40:29 +08:00
|
|
|
int b[2] = {
|
2010-04-17 04:56:35 +08:00
|
|
|
[1] = 22
|
2009-03-28 07:40:29 +08:00
|
|
|
};
|
2010-04-17 04:56:35 +08:00
|
|
|
|
2010-10-09 04:44:28 +08:00
|
|
|
// PR6955
|
|
|
|
|
|
|
|
struct ds {
|
|
|
|
struct {
|
|
|
|
struct {
|
|
|
|
short a;
|
|
|
|
};
|
|
|
|
short b;
|
|
|
|
struct {
|
|
|
|
short c;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// Traditional C anonymous member init
|
|
|
|
struct ds ds0 = { { { .a = 0 } } };
|
|
|
|
// C1X lookup-based anonymous member init cases
|
|
|
|
struct ds ds1 = { { .a = 1 } };
|
|
|
|
struct ds ds2 = { { .b = 1 } };
|
|
|
|
struct ds ds3 = { .a = 0 };
|
2011-07-12 13:53:08 +08:00
|
|
|
// CHECK: @ds4 = global %struct.ds { %struct.anon.3 { %struct.anon zeroinitializer, i16 0, %struct.anon.2 { i16 1 } } }
|
2010-10-09 04:44:28 +08:00
|
|
|
struct ds ds4 = { .c = 1 };
|
|
|
|
struct ds ds5 = { { { .a = 0 } }, .b = 1 };
|
|
|
|
struct ds ds6 = { { .a = 0, .b = 1 } };
|
2011-07-12 13:53:08 +08:00
|
|
|
// CHECK: @ds7 = global %struct.ds { %struct.anon.3 { %struct.anon { i16 2 }, i16 3, %struct.anon.2 zeroinitializer } }
|
2010-10-09 04:44:28 +08:00
|
|
|
struct ds ds7 = {
|
|
|
|
{ {
|
|
|
|
.a = 1
|
|
|
|
} },
|
|
|
|
.a = 2,
|
|
|
|
.b = 3
|
|
|
|
};
|
|
|
|
|
2010-09-06 08:13:11 +08:00
|
|
|
void test1(int argc, char **argv)
|
2010-04-17 04:56:35 +08:00
|
|
|
{
|
|
|
|
// CHECK: internal global %struct.foo { i8* null, i32 1024 }
|
|
|
|
static struct foo foo = {
|
|
|
|
.b = 1024,
|
|
|
|
};
|
|
|
|
|
2011-07-12 13:53:08 +08:00
|
|
|
// CHECK: bitcast %union.anon.4* %u2
|
2010-04-17 04:56:35 +08:00
|
|
|
// CHECK: call void @llvm.memset
|
|
|
|
union { int i; float f; } u2 = { };
|
|
|
|
|
|
|
|
// CHECK-NOT: call void @llvm.memset
|
|
|
|
union { int i; float f; } u3;
|
|
|
|
|
2010-09-06 08:13:11 +08:00
|
|
|
// CHECK: ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// PR7151
|
|
|
|
struct S {
|
|
|
|
int nkeys;
|
|
|
|
int *keys;
|
|
|
|
union {
|
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
void test2() {
|
|
|
|
struct S *btkr;
|
|
|
|
|
|
|
|
*btkr = (struct S) {
|
|
|
|
.keys = 0,
|
|
|
|
{ .data = 0 },
|
|
|
|
};
|
2010-04-17 04:56:35 +08:00
|
|
|
}
|