Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -arch i386 -verify -emit-llvm -o %t %s && |
Eli Friedman | cca196b | 2008-02-21 18:07:36 +0000 | [diff] [blame] | 2 | |
| 3 | #include <stdint.h> |
| 4 | |
| 5 | // Brace-enclosed string array initializers |
| 6 | char a[] = { "asdf" }; |
| 7 | |
| 8 | // Double-implicit-conversions of array/functions (not legal C, but |
| 9 | // clang accepts it for gcc compat). |
Daniel Dunbar | da8bf14 | 2008-08-05 06:30:41 +0000 | [diff] [blame] | 10 | intptr_t b = a; // expected-warning {{incompatible pointer to integer conversion}} |
Eli Friedman | cca196b | 2008-02-21 18:07:36 +0000 | [diff] [blame] | 11 | int c(); |
| 12 | void *d = c; |
Daniel Dunbar | da8bf14 | 2008-08-05 06:30:41 +0000 | [diff] [blame] | 13 | intptr_t e = c; // expected-warning {{incompatible pointer to integer conversion}} |
Eli Friedman | bc5ed6e | 2008-05-29 11:22:45 +0000 | [diff] [blame] | 14 | |
| 15 | int f, *g = __extension__ &f, *h = (1 != 1) ? &f : &f; |
Anders Carlsson | cd761cd | 2008-11-22 06:42:54 +0000 | [diff] [blame] | 16 | |
| 17 | union s2 { |
| 18 | struct { |
| 19 | struct { } *f0; |
| 20 | } f0; |
| 21 | }; |
| 22 | |
| 23 | int g0 = (int)(&(((union s2 *) 0)->f0.f0) - 0); |
Daniel Dunbar | a5fd07b | 2009-01-28 22:24:07 +0000 | [diff] [blame] | 24 | |
Chris Lattner | 6f877cd | 2009-03-01 00:59:19 +0000 | [diff] [blame] | 25 | // RUN: grep '@g1x = global %. { double 1.000000e+00, double 0.000000e+00 }' %t && |
Daniel Dunbar | 4087e24 | 2009-01-29 06:43:41 +0000 | [diff] [blame] | 26 | _Complex double g1x = 1.0f; |
Chris Lattner | 6f877cd | 2009-03-01 00:59:19 +0000 | [diff] [blame] | 27 | // RUN: grep '@g1y = global %. { double 0.000000e+00, double 1.000000e+00 }' %t && |
Daniel Dunbar | 4087e24 | 2009-01-29 06:43:41 +0000 | [diff] [blame] | 28 | _Complex double g1y = 1.0fi; |
Chris Lattner | 6f877cd | 2009-03-01 00:59:19 +0000 | [diff] [blame] | 29 | // RUN: grep '@g1 = global %. { i8 1, i8 10 }' %t && |
Daniel Dunbar | 4087e24 | 2009-01-29 06:43:41 +0000 | [diff] [blame] | 30 | _Complex char g1 = (char) 1 + (char) 10 * 1i; |
Eli Friedman | 48f9122 | 2009-03-28 03:24:54 +0000 | [diff] [blame] | 31 | // RUN: grep '@g2 = global %2 { i32 1, i32 10 }' %t && |
Daniel Dunbar | 4087e24 | 2009-01-29 06:43:41 +0000 | [diff] [blame] | 32 | _Complex int g2 = 1 + 10i; |
Chris Lattner | 6f877cd | 2009-03-01 00:59:19 +0000 | [diff] [blame] | 33 | // RUN: grep '@g3 = global %. { float 1.000000e+00, float 1.000000e+01 }' %t && |
Daniel Dunbar | 4087e24 | 2009-01-29 06:43:41 +0000 | [diff] [blame] | 34 | _Complex float g3 = 1.0 + 10.0i; |
Chris Lattner | 6f877cd | 2009-03-01 00:59:19 +0000 | [diff] [blame] | 35 | // RUN: grep '@g4 = global %. { double 1.000000e+00, double 1.000000e+01 }' %t && |
Daniel Dunbar | 4087e24 | 2009-01-29 06:43:41 +0000 | [diff] [blame] | 36 | _Complex double g4 = 1.0 + 10.0i; |
Eli Friedman | 48f9122 | 2009-03-28 03:24:54 +0000 | [diff] [blame] | 37 | // RUN: grep '@g5 = global %2 zeroinitializer' %t && |
Daniel Dunbar | 4087e24 | 2009-01-29 06:43:41 +0000 | [diff] [blame] | 38 | _Complex int g5 = (2 + 3i) == (5 + 7i); |
Chris Lattner | 6f877cd | 2009-03-01 00:59:19 +0000 | [diff] [blame] | 39 | // RUN: grep '@g6 = global %. { double -1.100000e+01, double 2.900000e+01 }' %t && |
Daniel Dunbar | 4087e24 | 2009-01-29 06:43:41 +0000 | [diff] [blame] | 40 | _Complex double g6 = (2.0 + 3.0i) * (5.0 + 7.0i); |
| 41 | // RUN: grep '@g7 = global i32 1' %t && |
| 42 | int g7 = (2 + 3i) * (5 + 7i) == (-11 + 29i); |
| 43 | // RUN: grep '@g8 = global i32 1' %t && |
| 44 | int g8 = (2.0 + 3.0i) * (5.0 + 7.0i) == (-11.0 + 29.0i); |
| 45 | // RUN: grep '@g9 = global i32 0' %t && |
| 46 | int g9 = (2 + 3i) * (5 + 7i) != (-11 + 29i); |
| 47 | // RUN: grep '@g10 = global i32 0' %t && |
| 48 | int g10 = (2.0 + 3.0i) * (5.0 + 7.0i) != (-11.0 + 29.0i); |
| 49 | |
| 50 | |
Daniel Dunbar | dd21164 | 2009-02-19 22:24:01 +0000 | [diff] [blame] | 51 | // Global references |
| 52 | // RUN: grep '@g11.l0 = internal global i32 ptrtoint (i32 ()\* @g11 to i32)' %t && |
| 53 | long g11() { |
| 54 | static long l0 = (long) g11; |
| 55 | return l0; |
| 56 | } |
| 57 | |
| 58 | // RUN: grep '@g12 = global i32 ptrtoint (i8\* @g12_tmp to i32)' %t && |
| 59 | static char g12_tmp; |
| 60 | long g12 = (long) &g12_tmp; |
| 61 | |
| 62 | // RUN: grep '@g13 = global \[1 x .struct.g13_s0\] \[.struct.g13_s0 <{ i32 ptrtoint (i8\* @g12_tmp to i32) }>\]' %t && |
| 63 | struct g13_s0 { |
| 64 | long a; |
| 65 | }; |
| 66 | struct g13_s0 g13[] = { |
| 67 | { (long) &g12_tmp } |
| 68 | }; |
| 69 | |
| 70 | // RUN: grep '@g14 = global i8\* inttoptr (i64 100 to i8\*)' %t && |
| 71 | void *g14 = (void*) 100; |
| 72 | |
| 73 | // RUN: grep '@g15 = global i32 -1' %t && |
| 74 | int g15 = (int) (char) ((void*) 0 + 255); |
| 75 | |
| 76 | // RUN: grep '@g16 = global i64 4294967295' %t && |
| 77 | long long g16 = (long long) ((void*) 0xFFFFFFFF); |
| 78 | |
Daniel Dunbar | 69ab26a | 2009-02-20 18:22:23 +0000 | [diff] [blame] | 79 | // RUN: grep '@g17 = global i32\* @g15' %t && |
| 80 | int *g17 = (int *) ((long) &g15); |
| 81 | |
Daniel Dunbar | d01b669 | 2009-02-24 18:41:57 +0000 | [diff] [blame] | 82 | // RUN: grep '@g18.p = internal global \[1 x i32\*\] \[i32\* @g19\]' %t && |
Daniel Dunbar | d01b669 | 2009-02-24 18:41:57 +0000 | [diff] [blame] | 83 | void g18(void) { |
| 84 | extern int g19; |
| 85 | static int *p[] = { &g19 }; |
| 86 | } |
| 87 | |
Daniel Dunbar | e5731f8 | 2009-02-25 20:08:33 +0000 | [diff] [blame] | 88 | // RUN: grep '@g20.l0 = internal global .struct.g20_s1 <{ .struct.g20_s0\* null, .struct.g20_s0\*\* getelementptr (.struct.g20_s1\* @g20.l0, i32 0, i32 0) }>' %t && |
| 89 | |
| 90 | struct g20_s0; |
| 91 | struct g20_s1 { |
| 92 | struct g20_s0 *f0, **f1; |
| 93 | }; |
| 94 | void *g20(void) { |
| 95 | static struct g20_s1 l0 = { ((void*) 0), &l0.f0 }; |
| 96 | return l0.f1; |
| 97 | } |
| 98 | |
Daniel Dunbar | 4087e24 | 2009-01-29 06:43:41 +0000 | [diff] [blame] | 99 | // RUN: true |