summaryrefslogtreecommitdiffstats
path: root/test/CodeGen/decl.c
blob: 29520d77ff488a90d8487e73cdcbfd67bbe203ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// RUN: %clang_cc1 -w -emit-llvm < %s | FileCheck %s

// CHECK: @test1.x = internal constant [12 x i32] [i32 1
// CHECK: @test2.x = internal unnamed_addr constant [13 x i32] [i32 1,
// CHECK: @test5w = global %0 { i32 2, [4 x i8] undef }
// CHECK: @test5y = global %union.test5u { double 7.300000e+0{{[0]*}}1 }

// CHECK: @test6.x = internal unnamed_addr constant %struct.SelectDest { i8 1, i8 2, i32 3, i32 0 }

// CHECK: @test7 = global [2 x %struct.test7s] [%struct.test7s { i32 1, i32 2 }, %struct.test7s { i32 4, i32 0 }]

void test1() {
  // This should codegen as a "@test1.x" global.
  const int x[] = { 1, 2, 3, 4, 6, 8, 9, 10, 123, 231, 123,23 };
  foo(x);

// CHECK: @test1()
// CHECK: {{call.*@foo.*@test1.x}}
}


// rdar://7346691
void test2() {
  // This should codegen as a "@test2.x" global + memcpy.
  int x[] = { 1, 2, 3, 4, 6, 8, 9, 10, 123, 231, 123,23, 24 };
  foo(x);
  
  // CHECK: @test2()
  // CHECK: %x = alloca [13 x i32]
  // CHECK: call void @llvm.memcpy
  // CHECK: call{{.*}}@foo{{.*}}i32* %
}


void test3() {
  // This should codegen as a memset.
  int x[100] = { 0 };
  foo(x);
  
  // CHECK: @test3()
  // CHECK: %x = alloca [100 x i32]
  // CHECK: call void @llvm.memset
}

void test4(void) {
  char a[10] = "asdf";
  char b[10] = { "asdf" };
  // CHECK: @test4()
  // CHECK: %a = alloca [10 x i8]
  // CHECK: %b = alloca [10 x i8]
  // CHECK: call void @llvm.memcpy
  // CHECK: call void @llvm.memcpy
}


union test5u { int i; double d; };

void test5() {
  union test5u ola = (union test5u) 351;
  union test5u olb = (union test5u) 1.0;
}

union test5u test5w = (union test5u)2;
union test5u test5y = (union test5u)73.0;



// PR6660 - sqlite miscompile
struct SelectDest {
  unsigned char eDest;
  unsigned char affinity;
  int iParm;
  int iMem;
};

void test6() {
  struct SelectDest x = {1, 2, 3};
  test6f(&x);
}

// rdar://7657600
struct test7s { int a; int b; } test7[] = {
  {1, 2},
  {4},
};

// rdar://7872531
#pragma pack(push, 2)
struct test8s { int f0; char f1; } test8g = {};


// PR7519

struct S {
  void (*x) (struct S *);
};

extern struct S *global_dc;
void cp_diagnostic_starter(struct S *);

void init_error(void) {
  global_dc->x = cp_diagnostic_starter;
}



// rdar://8147692 - ABI crash in recursive struct-through-function-pointer.
typedef struct {
  int x5a;
} x5;

typedef struct x2 *x0;
typedef long (*x1)(x0 x0a, x5 x6);
struct x2 {
  x1 x4;
};
long x3(x0 x0a, x5 a) {
  return x0a->x4(x0a, a);
}
OpenPOWER on IntegriCloud