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