blob: ee1d1701ee2ed8852932924fa8bfe0d07d6c7e9c [file] [log] [blame]
Nuno Lopescdb30b42010-04-16 20:56:35 +00001// RUN: %clang_cc1 -triple i386-unknown-unknown %s -emit-llvm -o - | FileCheck %s
Nuno Lopes5b2c6d92009-01-30 12:58:18 +00002
Douglas Gregor3498bdb2009-01-29 17:44:32 +00003struct foo {
4 void *a;
5 int b;
6};
7
Nuno Lopescdb30b42010-04-16 20:56:35 +00008// CHECK: @u = global %union.anon zeroinitializer
Douglas Gregor3498bdb2009-01-29 17:44:32 +00009union { int i; float f; } u = { };
10
Chris Lattnerc5cbb902011-06-20 04:01:35 +000011// CHECK: @u2 = global %2 { i32 0, [4 x i8] undef }
Nuno Lopescdb30b42010-04-16 20:56:35 +000012union { int i; double f; } u2 = { };
13
Chris Lattnerc5cbb902011-06-20 04:01:35 +000014// CHECK: @u3 = global %3 zeroinitializer
Nuno Lopes69cf5de2010-04-16 21:19:39 +000015union { double f; int i; } u3 = { };
16
Nuno Lopescdb30b42010-04-16 20:56:35 +000017// CHECK: @b = global [2 x i32] [i32 0, i32 22]
18int b[2] = {
19 [1] = 22
20};
21
Douglas Gregor022d13d2010-10-08 20:44:28 +000022// PR6955
23
24struct ds {
25 struct {
26 struct {
27 short a;
28 };
29 short b;
30 struct {
31 short c;
32 };
33 };
34};
35
36// Traditional C anonymous member init
37struct ds ds0 = { { { .a = 0 } } };
38// C1X lookup-based anonymous member init cases
39struct ds ds1 = { { .a = 1 } };
40struct ds ds2 = { { .b = 1 } };
41struct ds ds3 = { .a = 0 };
Chris Lattnerc5cbb902011-06-20 04:01:35 +000042// CHECK: @ds4 = global %struct.ds { %1 { %struct.anon zeroinitializer, i16 0, %struct.anon { i16 1 } } }
Douglas Gregor022d13d2010-10-08 20:44:28 +000043struct ds ds4 = { .c = 1 };
44struct ds ds5 = { { { .a = 0 } }, .b = 1 };
45struct ds ds6 = { { .a = 0, .b = 1 } };
Chris Lattnerc5cbb902011-06-20 04:01:35 +000046// CHECK: @ds7 = global %struct.ds { %1 { %struct.anon { i16 2 }, i16 3, %struct.anon zeroinitializer } }
Douglas Gregor022d13d2010-10-08 20:44:28 +000047struct ds ds7 = {
48 { {
49 .a = 1
50 } },
51 .a = 2,
52 .b = 3
53};
54
Chris Lattnerbd7de382010-09-06 00:13:11 +000055void test1(int argc, char **argv)
Douglas Gregor3498bdb2009-01-29 17:44:32 +000056{
Nuno Lopescdb30b42010-04-16 20:56:35 +000057 // CHECK: internal global %struct.foo { i8* null, i32 1024 }
58 static struct foo foo = {
59 .b = 1024,
60 };
Douglas Gregor68c56de2009-03-27 23:40:29 +000061
Nuno Lopescdb30b42010-04-16 20:56:35 +000062 // CHECK: bitcast %union.anon* %u2
63 // CHECK: call void @llvm.memset
64 union { int i; float f; } u2 = { };
65
66 // CHECK-NOT: call void @llvm.memset
67 union { int i; float f; } u3;
68
Chris Lattnerbd7de382010-09-06 00:13:11 +000069 // CHECK: ret void
70}
71
72
73// PR7151
74struct S {
75 int nkeys;
76 int *keys;
77 union {
78 void *data;
79 };
80};
81
82void test2() {
83 struct S *btkr;
84
85 *btkr = (struct S) {
86 .keys = 0,
87 { .data = 0 },
88 };
Nuno Lopescdb30b42010-04-16 20:56:35 +000089}