Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple i386-pc-linux-gnu -ffreestanding -verify -emit-llvm -o - %s | FileCheck %s |
Eli Friedman | cca196b | 2008-02-21 18:07:36 +0000 | [diff] [blame] | 2 | |
Ken Dyck | baf524d | 2009-11-22 18:29:06 +0000 | [diff] [blame] | 3 | #include <stdint.h> |
Eli Friedman | cca196b | 2008-02-21 18:07:36 +0000 | [diff] [blame] | 4 | |
| 5 | // Brace-enclosed string array initializers |
| 6 | char a[] = { "asdf" }; |
Benjamin Kramer | 0483a6f | 2011-03-02 21:27:44 +0000 | [diff] [blame] | 7 | // CHECK: @a = global [5 x i8] c"asdf\00" |
| 8 | |
| 9 | char a2[2][5] = { "asdf" }; |
| 10 | // CHECK: @a2 = global [2 x [5 x i8]] {{\[}}[5 x i8] c"asdf\00", [5 x i8] zeroinitializer] |
Eli Friedman | cca196b | 2008-02-21 18:07:36 +0000 | [diff] [blame] | 11 | |
| 12 | // Double-implicit-conversions of array/functions (not legal C, but |
| 13 | // clang accepts it for gcc compat). |
Daniel Dunbar | da8bf14 | 2008-08-05 06:30:41 +0000 | [diff] [blame] | 14 | intptr_t b = a; // expected-warning {{incompatible pointer to integer conversion}} |
Eli Friedman | cca196b | 2008-02-21 18:07:36 +0000 | [diff] [blame] | 15 | int c(); |
| 16 | void *d = c; |
Daniel Dunbar | da8bf14 | 2008-08-05 06:30:41 +0000 | [diff] [blame] | 17 | intptr_t e = c; // expected-warning {{incompatible pointer to integer conversion}} |
Eli Friedman | bc5ed6e | 2008-05-29 11:22:45 +0000 | [diff] [blame] | 18 | |
| 19 | int f, *g = __extension__ &f, *h = (1 != 1) ? &f : &f; |
Anders Carlsson | cd761cd | 2008-11-22 06:42:54 +0000 | [diff] [blame] | 20 | |
| 21 | union s2 { |
| 22 | struct { |
| 23 | struct { } *f0; |
| 24 | } f0; |
| 25 | }; |
| 26 | |
| 27 | int g0 = (int)(&(((union s2 *) 0)->f0.f0) - 0); |
Daniel Dunbar | a5fd07b | 2009-01-28 22:24:07 +0000 | [diff] [blame] | 28 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 29 | // CHECK: @g1x = global { double, double } { double 1.000000e+00{{[0]*}}, double 0.000000e+00{{[0]*}} } |
Daniel Dunbar | 4087e24 | 2009-01-29 06:43:41 +0000 | [diff] [blame] | 30 | _Complex double g1x = 1.0f; |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 31 | // CHECK: @g1y = global { double, double } { double 0.000000e+00{{[0]*}}, double 1.000000e+00{{[0]*}} } |
Daniel Dunbar | 4087e24 | 2009-01-29 06:43:41 +0000 | [diff] [blame] | 32 | _Complex double g1y = 1.0fi; |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 33 | // CHECK: @g1 = global { i8, i8 } { i8 1, i8 10 } |
Daniel Dunbar | 4087e24 | 2009-01-29 06:43:41 +0000 | [diff] [blame] | 34 | _Complex char g1 = (char) 1 + (char) 10 * 1i; |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 35 | // CHECK: @g2 = global { i32, i32 } { i32 1, i32 10 } |
Daniel Dunbar | 4087e24 | 2009-01-29 06:43:41 +0000 | [diff] [blame] | 36 | _Complex int g2 = 1 + 10i; |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 37 | // CHECK: @g3 = global { float, float } { float 1.000000e+00{{[0]*}}, float 1.000000e+0{{[0]*}}1 } |
Daniel Dunbar | 4087e24 | 2009-01-29 06:43:41 +0000 | [diff] [blame] | 38 | _Complex float g3 = 1.0 + 10.0i; |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 39 | // CHECK: @g4 = global { double, double } { double 1.000000e+00{{[0]*}}, double 1.000000e+0{{[0]*}}1 } |
Daniel Dunbar | 4087e24 | 2009-01-29 06:43:41 +0000 | [diff] [blame] | 40 | _Complex double g4 = 1.0 + 10.0i; |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 41 | // CHECK: @g5 = global { i32, i32 } zeroinitializer |
Daniel Dunbar | 4087e24 | 2009-01-29 06:43:41 +0000 | [diff] [blame] | 42 | _Complex int g5 = (2 + 3i) == (5 + 7i); |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 43 | // CHECK: @g6 = global { double, double } { double -1.100000e+0{{[0]*}}1, double 2.900000e+0{{[0]*}}1 } |
Daniel Dunbar | 4087e24 | 2009-01-29 06:43:41 +0000 | [diff] [blame] | 44 | _Complex double g6 = (2.0 + 3.0i) * (5.0 + 7.0i); |
Benjamin Kramer | d9097ff | 2009-10-02 10:32:51 +0000 | [diff] [blame] | 45 | // CHECK: @g7 = global i32 1 |
Daniel Dunbar | 4087e24 | 2009-01-29 06:43:41 +0000 | [diff] [blame] | 46 | int g7 = (2 + 3i) * (5 + 7i) == (-11 + 29i); |
Benjamin Kramer | d9097ff | 2009-10-02 10:32:51 +0000 | [diff] [blame] | 47 | // CHECK: @g8 = global i32 1 |
Daniel Dunbar | 4087e24 | 2009-01-29 06:43:41 +0000 | [diff] [blame] | 48 | int g8 = (2.0 + 3.0i) * (5.0 + 7.0i) == (-11.0 + 29.0i); |
Benjamin Kramer | d9097ff | 2009-10-02 10:32:51 +0000 | [diff] [blame] | 49 | // CHECK: @g9 = global i32 0 |
Daniel Dunbar | 4087e24 | 2009-01-29 06:43:41 +0000 | [diff] [blame] | 50 | int g9 = (2 + 3i) * (5 + 7i) != (-11 + 29i); |
Benjamin Kramer | d9097ff | 2009-10-02 10:32:51 +0000 | [diff] [blame] | 51 | // CHECK: @g10 = global i32 0 |
Daniel Dunbar | 4087e24 | 2009-01-29 06:43:41 +0000 | [diff] [blame] | 52 | int g10 = (2.0 + 3.0i) * (5.0 + 7.0i) != (-11.0 + 29.0i); |
| 53 | |
Anders Carlsson | 31f2f9c | 2009-10-02 02:15:20 +0000 | [diff] [blame] | 54 | // PR5108 |
Chris Lattner | cd87d1e | 2011-07-12 05:53:08 +0000 | [diff] [blame] | 55 | // CHECK: @gv1 = global %struct.anon <{ i32 0, i8 7 }>, align 1 |
Anders Carlsson | 2df96e7 | 2009-10-02 04:52:12 +0000 | [diff] [blame] | 56 | struct { |
Anders Carlsson | 31f2f9c | 2009-10-02 02:15:20 +0000 | [diff] [blame] | 57 | unsigned long a; |
| 58 | unsigned long b:3; |
Anders Carlsson | 2df96e7 | 2009-10-02 04:52:12 +0000 | [diff] [blame] | 59 | } __attribute__((__packed__)) gv1 = { .a = 0x0, .b = 7, }; |
| 60 | |
| 61 | // PR5118 |
Chris Lattner | cd87d1e | 2011-07-12 05:53:08 +0000 | [diff] [blame] | 62 | // CHECK: @gv2 = global %struct.anon.0 <{ i8 1, i8* null }>, align 1 |
Anders Carlsson | 2df96e7 | 2009-10-02 04:52:12 +0000 | [diff] [blame] | 63 | struct { |
| 64 | unsigned char a; |
| 65 | char *b; |
| 66 | } __attribute__((__packed__)) gv2 = { 1, (void*)0 }; |
Daniel Dunbar | 4087e24 | 2009-01-29 06:43:41 +0000 | [diff] [blame] | 67 | |
Daniel Dunbar | dd21164 | 2009-02-19 22:24:01 +0000 | [diff] [blame] | 68 | // Global references |
Benjamin Kramer | d9097ff | 2009-10-02 10:32:51 +0000 | [diff] [blame] | 69 | // CHECK: @g11.l0 = internal global i32 ptrtoint (i32 ()* @g11 to i32) |
Daniel Dunbar | dd21164 | 2009-02-19 22:24:01 +0000 | [diff] [blame] | 70 | long g11() { |
| 71 | static long l0 = (long) g11; |
| 72 | return l0; |
| 73 | } |
| 74 | |
Benjamin Kramer | d9097ff | 2009-10-02 10:32:51 +0000 | [diff] [blame] | 75 | // CHECK: @g12 = global i32 ptrtoint (i8* @g12_tmp to i32) |
Daniel Dunbar | dd21164 | 2009-02-19 22:24:01 +0000 | [diff] [blame] | 76 | static char g12_tmp; |
| 77 | long g12 = (long) &g12_tmp; |
| 78 | |
Benjamin Kramer | d9097ff | 2009-10-02 10:32:51 +0000 | [diff] [blame] | 79 | // CHECK: @g13 = global [1 x %struct.g13_s0] [%struct.g13_s0 { i32 ptrtoint (i8* @g12_tmp to i32) }] |
Daniel Dunbar | dd21164 | 2009-02-19 22:24:01 +0000 | [diff] [blame] | 80 | struct g13_s0 { |
| 81 | long a; |
| 82 | }; |
| 83 | struct g13_s0 g13[] = { |
| 84 | { (long) &g12_tmp } |
| 85 | }; |
| 86 | |
Benjamin Kramer | d9097ff | 2009-10-02 10:32:51 +0000 | [diff] [blame] | 87 | // CHECK: @g14 = global i8* inttoptr (i64 100 to i8*) |
Daniel Dunbar | dd21164 | 2009-02-19 22:24:01 +0000 | [diff] [blame] | 88 | void *g14 = (void*) 100; |
| 89 | |
Benjamin Kramer | d9097ff | 2009-10-02 10:32:51 +0000 | [diff] [blame] | 90 | // CHECK: @g15 = global i32 -1 |
Daniel Dunbar | dd21164 | 2009-02-19 22:24:01 +0000 | [diff] [blame] | 91 | int g15 = (int) (char) ((void*) 0 + 255); |
| 92 | |
Benjamin Kramer | d9097ff | 2009-10-02 10:32:51 +0000 | [diff] [blame] | 93 | // CHECK: @g16 = global i64 4294967295 |
Daniel Dunbar | dd21164 | 2009-02-19 22:24:01 +0000 | [diff] [blame] | 94 | long long g16 = (long long) ((void*) 0xFFFFFFFF); |
| 95 | |
Benjamin Kramer | d9097ff | 2009-10-02 10:32:51 +0000 | [diff] [blame] | 96 | // CHECK: @g17 = global i32* @g15 |
Daniel Dunbar | 69ab26a | 2009-02-20 18:22:23 +0000 | [diff] [blame] | 97 | int *g17 = (int *) ((long) &g15); |
| 98 | |
Benjamin Kramer | d9097ff | 2009-10-02 10:32:51 +0000 | [diff] [blame] | 99 | // CHECK: @g18.p = internal global [1 x i32*] [i32* @g19] |
Daniel Dunbar | d01b669 | 2009-02-24 18:41:57 +0000 | [diff] [blame] | 100 | void g18(void) { |
| 101 | extern int g19; |
| 102 | static int *p[] = { &g19 }; |
| 103 | } |
| 104 | |
Benjamin Kramer | d9097ff | 2009-10-02 10:32:51 +0000 | [diff] [blame] | 105 | // CHECK: @g20.l0 = internal global %struct.g20_s1 { %struct.g20_s0* null, %struct.g20_s0** getelementptr inbounds (%struct.g20_s1* @g20.l0, i32 0, i32 0) } |
Daniel Dunbar | e5731f8 | 2009-02-25 20:08:33 +0000 | [diff] [blame] | 106 | struct g20_s0; |
| 107 | struct g20_s1 { |
| 108 | struct g20_s0 *f0, **f1; |
| 109 | }; |
| 110 | void *g20(void) { |
| 111 | static struct g20_s1 l0 = { ((void*) 0), &l0.f0 }; |
| 112 | return l0.f1; |
| 113 | } |
| 114 | |
Eli Friedman | 944af71 | 2009-04-30 07:03:22 +0000 | [diff] [blame] | 115 | // PR4108 |
| 116 | struct g21 {int g21;}; |
| 117 | const struct g21 g21 = (struct g21){1}; |
Eli Friedman | 64241fc | 2009-11-13 21:23:46 +0000 | [diff] [blame] | 118 | |
| 119 | // PR5474 |
| 120 | struct g22 {int x;} __attribute((packed)); |
| 121 | struct g23 {char a; short b; char c; struct g22 d;}; |
| 122 | struct g23 g24 = {1,2,3,4}; |
| 123 | |
Eli Friedman | f70b24e | 2009-11-14 08:37:13 +0000 | [diff] [blame] | 124 | // CHECK: @g25.g26 = internal global i8* getelementptr inbounds ([4 x i8]* @__func__.g25, i32 0, i32 0) |
Rafael Espindola | 1257bc6 | 2011-01-10 22:34:03 +0000 | [diff] [blame] | 125 | // CHECK: @__func__.g25 = private unnamed_addr constant [4 x i8] c"g25\00" |
Eli Friedman | f70b24e | 2009-11-14 08:37:13 +0000 | [diff] [blame] | 126 | int g25() { |
| 127 | static const char *g26 = __func__; |
| 128 | return *g26; |
| 129 | } |
John McCall | 9c20fa9 | 2010-09-03 18:58:50 +0000 | [diff] [blame] | 130 | |
| 131 | // CHECK: @g27.x = internal global i8* bitcast (i8** @g27.x to i8*), align 4 |
| 132 | void g27() { // PR8073 |
| 133 | static void *x = &x; |
| 134 | } |
Eli Friedman | e6a24e8 | 2011-12-22 03:51:45 +0000 | [diff] [blame] | 135 | |
| 136 | void g28() { |
| 137 | typedef long long v1i64 __attribute((vector_size(8))); |
| 138 | typedef short v12i16 __attribute((vector_size(24))); |
| 139 | typedef long double v2f80 __attribute((vector_size(24))); |
| 140 | // CHECK: @g28.a = internal global <1 x i64> <i64 10> |
| 141 | // CHECK: @g28.b = internal global <12 x i16> <i16 0, i16 0, i16 0, i16 -32768, i16 16383, i16 0, i16 0, i16 0, i16 0, i16 -32768, i16 16384, i16 0> |
| 142 | // CHECK: @g28.c = internal global <2 x x86_fp80> <x86_fp80 0xK3FFF8000000000000000, x86_fp80 0xK40008000000000000000>, align 32 |
| 143 | static v1i64 a = (v1i64)10LL; |
| 144 | static v12i16 b = (v2f80){1,2}; |
| 145 | static v2f80 c = (v12i16){0,0,0,-32768,16383,0,0,0,0,-32768,16384,0}; |
| 146 | } |