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