blob: 296a01d8a4b630f6bdd5f60454744f532b1fdc5e [file] [log] [blame]
Anders Carlsson39e3eb12009-10-02 02:15:20 +00001// RUN: clang-cc -triple i386-pc-linux-gnu -verify -emit-llvm -o %t %s | FileCheck %s --input-file=%t &&
Eli Friedmanc62dd9d2008-02-21 18:07:36 +00002
3#include <stdint.h>
4
5// Brace-enclosed string array initializers
6char a[] = { "asdf" };
7
8// Double-implicit-conversions of array/functions (not legal C, but
9// clang accepts it for gcc compat).
Daniel Dunbard548c792008-08-05 06:30:41 +000010intptr_t b = a; // expected-warning {{incompatible pointer to integer conversion}}
Eli Friedmanc62dd9d2008-02-21 18:07:36 +000011int c();
12void *d = c;
Daniel Dunbard548c792008-08-05 06:30:41 +000013intptr_t e = c; // expected-warning {{incompatible pointer to integer conversion}}
Eli Friedman045bf4f2008-05-29 11:22:45 +000014
15int f, *g = __extension__ &f, *h = (1 != 1) ? &f : &f;
Anders Carlsson4d5f2e52008-11-22 06:42:54 +000016
17union s2 {
18 struct {
19 struct { } *f0;
20 } f0;
21};
22
23int g0 = (int)(&(((union s2 *) 0)->f0.f0) - 0);
Daniel Dunbarf50e60b2009-01-28 22:24:07 +000024
Chris Lattnere87da662009-03-01 00:59:19 +000025// RUN: grep '@g1x = global %. { double 1.000000e+00, double 0.000000e+00 }' %t &&
Daniel Dunbar74f2425b2009-01-29 06:43:41 +000026_Complex double g1x = 1.0f;
Chris Lattnere87da662009-03-01 00:59:19 +000027// RUN: grep '@g1y = global %. { double 0.000000e+00, double 1.000000e+00 }' %t &&
Daniel Dunbar74f2425b2009-01-29 06:43:41 +000028_Complex double g1y = 1.0fi;
Chris Lattnere87da662009-03-01 00:59:19 +000029// RUN: grep '@g1 = global %. { i8 1, i8 10 }' %t &&
Daniel Dunbar74f2425b2009-01-29 06:43:41 +000030_Complex char g1 = (char) 1 + (char) 10 * 1i;
Eli Friedman09a9b6e2009-03-28 03:24:54 +000031// RUN: grep '@g2 = global %2 { i32 1, i32 10 }' %t &&
Daniel Dunbar74f2425b2009-01-29 06:43:41 +000032_Complex int g2 = 1 + 10i;
Chris Lattnere87da662009-03-01 00:59:19 +000033// RUN: grep '@g3 = global %. { float 1.000000e+00, float 1.000000e+01 }' %t &&
Daniel Dunbar74f2425b2009-01-29 06:43:41 +000034_Complex float g3 = 1.0 + 10.0i;
Chris Lattnere87da662009-03-01 00:59:19 +000035// RUN: grep '@g4 = global %. { double 1.000000e+00, double 1.000000e+01 }' %t &&
Daniel Dunbar74f2425b2009-01-29 06:43:41 +000036_Complex double g4 = 1.0 + 10.0i;
Eli Friedman09a9b6e2009-03-28 03:24:54 +000037// RUN: grep '@g5 = global %2 zeroinitializer' %t &&
Daniel Dunbar74f2425b2009-01-29 06:43:41 +000038_Complex int g5 = (2 + 3i) == (5 + 7i);
Chris Lattnere87da662009-03-01 00:59:19 +000039// RUN: grep '@g6 = global %. { double -1.100000e+01, double 2.900000e+01 }' %t &&
Daniel Dunbar74f2425b2009-01-29 06:43:41 +000040_Complex double g6 = (2.0 + 3.0i) * (5.0 + 7.0i);
41// RUN: grep '@g7 = global i32 1' %t &&
42int g7 = (2 + 3i) * (5 + 7i) == (-11 + 29i);
43// RUN: grep '@g8 = global i32 1' %t &&
44int g8 = (2.0 + 3.0i) * (5.0 + 7.0i) == (-11.0 + 29.0i);
45// RUN: grep '@g9 = global i32 0' %t &&
46int g9 = (2 + 3i) * (5 + 7i) != (-11 + 29i);
47// RUN: grep '@g10 = global i32 0' %t &&
48int g10 = (2.0 + 3.0i) * (5.0 + 7.0i) != (-11.0 + 29.0i);
49
Anders Carlsson39e3eb12009-10-02 02:15:20 +000050// PR5108
Anders Carlsson8a744ad2009-10-02 04:52:12 +000051// CHECK: @gv1 = global %4 <{ i32 0, i8 7 }>, align 1
52struct {
Anders Carlsson39e3eb12009-10-02 02:15:20 +000053 unsigned long a;
54 unsigned long b:3;
Anders Carlsson8a744ad2009-10-02 04:52:12 +000055} __attribute__((__packed__)) gv1 = { .a = 0x0, .b = 7, };
56
57// PR5118
58// CHECK: @gv2 = global %5 <{ i8 1, i8* null }>, align 1
59struct {
60 unsigned char a;
61 char *b;
62} __attribute__((__packed__)) gv2 = { 1, (void*)0 };
Daniel Dunbar74f2425b2009-01-29 06:43:41 +000063
Daniel Dunbar1c8560d2009-02-19 22:24:01 +000064// Global references
65// RUN: grep '@g11.l0 = internal global i32 ptrtoint (i32 ()\* @g11 to i32)' %t &&
66long g11() {
67 static long l0 = (long) g11;
68 return l0;
69}
70
71// RUN: grep '@g12 = global i32 ptrtoint (i8\* @g12_tmp to i32)' %t &&
72static char g12_tmp;
73long g12 = (long) &g12_tmp;
74
Anders Carlsson72fb3842009-07-27 15:31:55 +000075// RUN: grep '@g13 = global \[1 x %.truct.g13_s0\] \[%.truct.g13_s0 { i32 ptrtoint (i8\* @g12_tmp to i32) }\]' %t &&
Daniel Dunbar1c8560d2009-02-19 22:24:01 +000076struct g13_s0 {
77 long a;
78};
79struct g13_s0 g13[] = {
80 { (long) &g12_tmp }
81};
82
83// RUN: grep '@g14 = global i8\* inttoptr (i64 100 to i8\*)' %t &&
84void *g14 = (void*) 100;
85
86// RUN: grep '@g15 = global i32 -1' %t &&
87int g15 = (int) (char) ((void*) 0 + 255);
88
89// RUN: grep '@g16 = global i64 4294967295' %t &&
90long long g16 = (long long) ((void*) 0xFFFFFFFF);
91
Daniel Dunbarce399542009-02-20 18:22:23 +000092// RUN: grep '@g17 = global i32\* @g15' %t &&
93int *g17 = (int *) ((long) &g15);
94
Daniel Dunbard4ecca12009-02-24 18:41:57 +000095// RUN: grep '@g18.p = internal global \[1 x i32\*\] \[i32\* @g19\]' %t &&
Daniel Dunbard4ecca12009-02-24 18:41:57 +000096void g18(void) {
97 extern int g19;
98 static int *p[] = { &g19 };
99}
100
Dan Gohman0533ffa2009-09-11 00:27:06 +0000101// RUN: grep '@g20.l0 = internal global %.truct.g20_s1 { %.truct.g20_s0\* null, %.truct.g20_s0\*\* getelementptr inbounds (%.truct.g20_s1\* @g20.l0, i32 0, i32 0) }' %t &&
Daniel Dunbar1cdbc542009-02-25 20:08:33 +0000102
103struct g20_s0;
104struct g20_s1 {
105 struct g20_s0 *f0, **f1;
106};
107void *g20(void) {
108 static struct g20_s1 l0 = { ((void*) 0), &l0.f0 };
109 return l0.f1;
110}
111
Eli Friedman902fddd2009-04-30 07:03:22 +0000112// PR4108
113struct g21 {int g21;};
114const struct g21 g21 = (struct g21){1};
115
Daniel Dunbar74f2425b2009-01-29 06:43:41 +0000116// RUN: true
Eli Friedman902fddd2009-04-30 07:03:22 +0000117