1*67e74705SXin Li // RUN: %clang_cc1 -w -emit-llvm < %s | FileCheck %s
2*67e74705SXin Li
3*67e74705SXin Li // CHECK: @test1.x = internal constant [12 x i32] [i32 1
4*67e74705SXin Li // CHECK: @test2.x = private unnamed_addr constant [13 x i32] [i32 1,
5*67e74705SXin Li // CHECK: @test5w = global { i32, [4 x i8] } { i32 2, [4 x i8] undef }
6*67e74705SXin Li // CHECK: @test5y = global { double } { double 7.300000e+0{{[0]*}}1 }
7*67e74705SXin Li
8*67e74705SXin Li // CHECK: @test6.x = private unnamed_addr constant %struct.SelectDest { i8 1, i8 2, i32 3, i32 0 }
9*67e74705SXin Li
10*67e74705SXin Li // CHECK: @test7 = global [2 x %struct.test7s] [%struct.test7s { i32 1, i32 2 }, %struct.test7s { i32 4, i32 0 }]
11*67e74705SXin Li
test1()12*67e74705SXin Li void test1() {
13*67e74705SXin Li // This should codegen as a "@test1.x" global.
14*67e74705SXin Li const int x[] = { 1, 2, 3, 4, 6, 8, 9, 10, 123, 231, 123,23 };
15*67e74705SXin Li foo(x);
16*67e74705SXin Li
17*67e74705SXin Li // CHECK: @test1()
18*67e74705SXin Li // CHECK: {{call.*@foo.*@test1.x}}
19*67e74705SXin Li }
20*67e74705SXin Li
21*67e74705SXin Li
22*67e74705SXin Li // rdar://7346691
test2()23*67e74705SXin Li void test2() {
24*67e74705SXin Li // This should codegen as a "@test2.x" global + memcpy.
25*67e74705SXin Li int x[] = { 1, 2, 3, 4, 6, 8, 9, 10, 123, 231, 123,23, 24 };
26*67e74705SXin Li foo(x);
27*67e74705SXin Li
28*67e74705SXin Li // CHECK: @test2()
29*67e74705SXin Li // CHECK: %x = alloca [13 x i32]
30*67e74705SXin Li // CHECK: call void @llvm.memcpy
31*67e74705SXin Li // CHECK: call{{.*}}@foo{{.*}}i32* %
32*67e74705SXin Li }
33*67e74705SXin Li
34*67e74705SXin Li
test3()35*67e74705SXin Li void test3() {
36*67e74705SXin Li // This should codegen as a memset.
37*67e74705SXin Li int x[100] = { 0 };
38*67e74705SXin Li foo(x);
39*67e74705SXin Li
40*67e74705SXin Li // CHECK: @test3()
41*67e74705SXin Li // CHECK: %x = alloca [100 x i32]
42*67e74705SXin Li // CHECK: call void @llvm.memset
43*67e74705SXin Li }
44*67e74705SXin Li
test4(void)45*67e74705SXin Li void test4(void) {
46*67e74705SXin Li char a[10] = "asdf";
47*67e74705SXin Li char b[10] = { "asdf" };
48*67e74705SXin Li // CHECK: @test4()
49*67e74705SXin Li // CHECK: %a = alloca [10 x i8]
50*67e74705SXin Li // CHECK: %b = alloca [10 x i8]
51*67e74705SXin Li // CHECK: call void @llvm.memcpy
52*67e74705SXin Li // CHECK: call void @llvm.memcpy
53*67e74705SXin Li }
54*67e74705SXin Li
55*67e74705SXin Li
56*67e74705SXin Li union test5u { int i; double d; };
57*67e74705SXin Li
test5()58*67e74705SXin Li void test5() {
59*67e74705SXin Li union test5u ola = (union test5u) 351;
60*67e74705SXin Li union test5u olb = (union test5u) 1.0;
61*67e74705SXin Li }
62*67e74705SXin Li
63*67e74705SXin Li union test5u test5w = (union test5u)2;
64*67e74705SXin Li union test5u test5y = (union test5u)73.0;
65*67e74705SXin Li
66*67e74705SXin Li
67*67e74705SXin Li
68*67e74705SXin Li // PR6660 - sqlite miscompile
69*67e74705SXin Li struct SelectDest {
70*67e74705SXin Li unsigned char eDest;
71*67e74705SXin Li unsigned char affinity;
72*67e74705SXin Li int iParm;
73*67e74705SXin Li int iMem;
74*67e74705SXin Li };
75*67e74705SXin Li
test6()76*67e74705SXin Li void test6() {
77*67e74705SXin Li struct SelectDest x = {1, 2, 3};
78*67e74705SXin Li test6f(&x);
79*67e74705SXin Li }
80*67e74705SXin Li
81*67e74705SXin Li // rdar://7657600
82*67e74705SXin Li struct test7s { int a; int b; } test7[] = {
83*67e74705SXin Li {1, 2},
84*67e74705SXin Li {4},
85*67e74705SXin Li };
86*67e74705SXin Li
87*67e74705SXin Li // rdar://7872531
88*67e74705SXin Li #pragma pack(push, 2)
89*67e74705SXin Li struct test8s { int f0; char f1; } test8g = {};
90*67e74705SXin Li
91*67e74705SXin Li
92*67e74705SXin Li // PR7519
93*67e74705SXin Li
94*67e74705SXin Li struct S {
95*67e74705SXin Li void (*x) (struct S *);
96*67e74705SXin Li };
97*67e74705SXin Li
98*67e74705SXin Li extern struct S *global_dc;
99*67e74705SXin Li void cp_diagnostic_starter(struct S *);
100*67e74705SXin Li
init_error(void)101*67e74705SXin Li void init_error(void) {
102*67e74705SXin Li global_dc->x = cp_diagnostic_starter;
103*67e74705SXin Li }
104*67e74705SXin Li
105*67e74705SXin Li
106*67e74705SXin Li
107*67e74705SXin Li // rdar://8147692 - ABI crash in recursive struct-through-function-pointer.
108*67e74705SXin Li typedef struct {
109*67e74705SXin Li int x5a;
110*67e74705SXin Li } x5;
111*67e74705SXin Li
112*67e74705SXin Li typedef struct x2 *x0;
113*67e74705SXin Li typedef long (*x1)(x0 x0a, x5 x6);
114*67e74705SXin Li struct x2 {
115*67e74705SXin Li x1 x4;
116*67e74705SXin Li };
x3(x0 x0a,x5 a)117*67e74705SXin Li long x3(x0 x0a, x5 a) {
118*67e74705SXin Li return x0a->x4(x0a, a);
119*67e74705SXin Li }
120