Nuno Lopes | a75b71f | 2010-04-18 19:06:43 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck %s |
Daniel Dunbar | e4c9238 | 2009-02-13 22:58:39 +0000 | [diff] [blame] | 2 | |
Lauro Ramos Venancio | 305762c | 2008-02-18 22:44:02 +0000 | [diff] [blame] | 3 | void f1() { |
| 4 | // Scalars in braces. |
| 5 | int a = { 1 }; |
Lauro Ramos Venancio | 305762c | 2008-02-18 22:44:02 +0000 | [diff] [blame] | 6 | } |
| 7 | |
| 8 | void f2() { |
| 9 | int a[2][2] = { { 1, 2 }, { 3, 4 } }; |
| 10 | int b[3][3] = { { 1, 2 }, { 3, 4 } }; |
| 11 | int *c[2] = { &a[1][1], &b[2][2] }; |
| 12 | int *d[2][2] = { {&a[1][1], &b[2][2]}, {&a[0][0], &b[1][1]} }; |
| 13 | int *e[3][3] = { {&a[1][1], &b[2][2]}, {&a[0][0], &b[1][1]} }; |
Lauro Ramos Venancio | 145cd89 | 2008-02-19 19:27:31 +0000 | [diff] [blame] | 14 | char ext[3][3] = {".Y",".U",".V"}; |
Anders Carlsson | a3881fc | 2008-01-29 01:28:48 +0000 | [diff] [blame] | 15 | } |
Chris Lattner | d3c3856 | 2008-05-04 00:56:25 +0000 | [diff] [blame] | 16 | |
| 17 | typedef void (* F)(void); |
| 18 | extern void foo(void); |
| 19 | struct S { F f; }; |
| 20 | void f3() { |
| 21 | struct S a[1] = { { foo } }; |
| 22 | } |
| 23 | |
Daniel Dunbar | e4c9238 | 2009-02-13 22:58:39 +0000 | [diff] [blame] | 24 | // Constants |
Nuno Lopes | a75b71f | 2010-04-18 19:06:43 +0000 | [diff] [blame] | 25 | // CHECK: @g3 = constant i32 10 |
| 26 | // CHECK: @f4.g4 = internal constant i32 12 |
Daniel Dunbar | e4c9238 | 2009-02-13 22:58:39 +0000 | [diff] [blame] | 27 | const int g3 = 10; |
| 28 | int f4() { |
| 29 | static const int g4 = 12; |
| 30 | return g4; |
| 31 | } |
Chris Lattner | b35baae | 2010-03-08 21:08:07 +0000 | [diff] [blame] | 32 | |
| 33 | // PR6537 |
| 34 | typedef union vec3 { |
| 35 | struct { double x, y, z; }; |
| 36 | double component[3]; |
| 37 | } vec3; |
| 38 | vec3 f5(vec3 value) { |
| 39 | return (vec3) {{ |
| 40 | .x = value.x |
| 41 | }}; |
| 42 | } |
John McCall | 0f2b692 | 2010-07-07 05:08:32 +0000 | [diff] [blame] | 43 | |
| 44 | // rdar://problem/8154689 |
| 45 | void f6() { |
| 46 | int x; |
| 47 | long ids[] = { (long) &x }; |
| 48 | } |
Chris Lattner | 9046c22 | 2010-10-10 17:49:49 +0000 | [diff] [blame] | 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | // CHECK: @test7 = global{{.*}}{ i32 0, [4 x i8] c"bar\00" } |
| 54 | // PR8217 |
| 55 | struct a7 { |
| 56 | int b; |
| 57 | char v[]; |
| 58 | }; |
| 59 | |
| 60 | struct a7 test7 = { .b = 0, .v = "bar" }; |
Chris Lattner | 70b0294 | 2010-12-02 01:58:41 +0000 | [diff] [blame] | 61 | |
| 62 | |
| 63 | // PR279 comment #3 |
| 64 | char test8(int X) { |
| 65 | char str[100000] = "abc"; // tail should be memset. |
| 66 | return str[X]; |
| 67 | // CHECK: @test8( |
| 68 | // CHECK: call void @llvm.memset |
| 69 | // CHECK: store i8 97 |
| 70 | // CHECK: store i8 98 |
| 71 | // CHECK: store i8 99 |
Benjamin Kramer | cfa07e3 | 2012-08-27 21:35:58 +0000 | [diff] [blame] | 72 | // CHECK-NOT: getelementptr |
| 73 | // CHECK: load |
Chris Lattner | 70b0294 | 2010-12-02 01:58:41 +0000 | [diff] [blame] | 74 | } |
Chris Lattner | 1b72677 | 2010-12-02 07:07:26 +0000 | [diff] [blame] | 75 | |
| 76 | void bar(void*); |
| 77 | |
| 78 | // PR279 |
| 79 | int test9(int X) { |
| 80 | int Arr[100] = { X }; // Should use memset |
| 81 | bar(Arr); |
| 82 | // CHECK: @test9 |
| 83 | // CHECK: call void @llvm.memset |
| 84 | // CHECK-NOT: store i32 0 |
| 85 | // CHECK: call void @bar |
| 86 | } |
| 87 | |
| 88 | struct a { |
| 89 | int a, b, c, d, e, f, g, h, i, j, k, *p; |
| 90 | }; |
| 91 | |
| 92 | struct b { |
| 93 | struct a a,b,c,d,e,f,g; |
| 94 | }; |
| 95 | |
| 96 | int test10(int X) { |
| 97 | struct b S = { .a.a = X, .d.e = X, .f.e = 0, .f.f = 0, .f.p = 0 }; |
| 98 | bar(&S); |
| 99 | |
| 100 | // CHECK: @test10 |
| 101 | // CHECK: call void @llvm.memset |
| 102 | // CHECK-NOT: store i32 0 |
| 103 | // CHECK: call void @bar |
| 104 | } |
Chris Lattner | e0fd832 | 2011-02-19 22:28:58 +0000 | [diff] [blame] | 105 | |
| 106 | |
| 107 | // PR9257 |
| 108 | struct test11S { |
| 109 | int A[10]; |
| 110 | }; |
| 111 | void test11(struct test11S *P) { |
| 112 | *P = (struct test11S) { .A = { [0 ... 3] = 4 } }; |
| 113 | // CHECK: @test11 |
| 114 | // CHECK: store i32 4 |
| 115 | // CHECK: store i32 4 |
| 116 | // CHECK: store i32 4 |
| 117 | // CHECK: store i32 4 |
| 118 | // CHECK: ret void |
| 119 | } |
Chris Lattner | f742eb0 | 2011-07-10 00:18:59 +0000 | [diff] [blame] | 120 | |
| 121 | |
| 122 | // Verify that we can convert a recursive struct with a memory that returns |
| 123 | // an instance of the struct we're converting. |
| 124 | struct test12 { |
| 125 | struct test12 (*p)(void); |
| 126 | } test12g; |
| 127 | |
Eli Friedman | 5a13d4d | 2012-02-24 23:53:49 +0000 | [diff] [blame] | 128 | |
| 129 | void test13(int x) { |
| 130 | struct X { int a; int b : 10; int c; }; |
| 131 | struct X y = {.c = x}; |
| 132 | // CHECK: @test13 |
Chandler Carruth | 72d2dab | 2012-12-06 11:14:44 +0000 | [diff] [blame] | 133 | // CHECK: and i16 {{.*}}, -1024 |
Eli Friedman | 5a13d4d | 2012-02-24 23:53:49 +0000 | [diff] [blame] | 134 | } |