2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -triple i386-pc-linux-gnu -ffreestanding -verify -emit-llvm -o - %s | FileCheck %s
|
2008-02-22 02:07:36 +08:00
|
|
|
|
2009-11-23 02:29:06 +08:00
|
|
|
#include <stdint.h>
|
2008-02-22 02:07:36 +08:00
|
|
|
|
|
|
|
// Brace-enclosed string array initializers
|
|
|
|
char a[] = { "asdf" };
|
2011-03-03 05:27:44 +08:00
|
|
|
// CHECK: @a = global [5 x i8] c"asdf\00"
|
|
|
|
|
|
|
|
char a2[2][5] = { "asdf" };
|
|
|
|
// CHECK: @a2 = global [2 x [5 x i8]] {{\[}}[5 x i8] c"asdf\00", [5 x i8] zeroinitializer]
|
2008-02-22 02:07:36 +08:00
|
|
|
|
|
|
|
// Double-implicit-conversions of array/functions (not legal C, but
|
|
|
|
// clang accepts it for gcc compat).
|
2008-08-05 14:30:41 +08:00
|
|
|
intptr_t b = a; // expected-warning {{incompatible pointer to integer conversion}}
|
2008-02-22 02:07:36 +08:00
|
|
|
int c();
|
|
|
|
void *d = c;
|
2008-08-05 14:30:41 +08:00
|
|
|
intptr_t e = c; // expected-warning {{incompatible pointer to integer conversion}}
|
2008-05-29 19:22:45 +08:00
|
|
|
|
|
|
|
int f, *g = __extension__ &f, *h = (1 != 1) ? &f : &f;
|
2008-11-22 14:42:54 +08:00
|
|
|
|
|
|
|
union s2 {
|
|
|
|
struct {
|
|
|
|
struct { } *f0;
|
|
|
|
} f0;
|
|
|
|
};
|
|
|
|
|
|
|
|
int g0 = (int)(&(((union s2 *) 0)->f0.f0) - 0);
|
2009-01-29 06:24:07 +08:00
|
|
|
|
2011-07-10 01:41:47 +08:00
|
|
|
// CHECK: @g1x = global { double, double } { double 1.000000e+00{{[0]*}}, double 0.000000e+00{{[0]*}} }
|
2009-01-29 14:43:41 +08:00
|
|
|
_Complex double g1x = 1.0f;
|
2011-07-10 01:41:47 +08:00
|
|
|
// CHECK: @g1y = global { double, double } { double 0.000000e+00{{[0]*}}, double 1.000000e+00{{[0]*}} }
|
2009-01-29 14:43:41 +08:00
|
|
|
_Complex double g1y = 1.0fi;
|
2011-07-10 01:41:47 +08:00
|
|
|
// CHECK: @g1 = global { i8, i8 } { i8 1, i8 10 }
|
2009-01-29 14:43:41 +08:00
|
|
|
_Complex char g1 = (char) 1 + (char) 10 * 1i;
|
2011-07-10 01:41:47 +08:00
|
|
|
// CHECK: @g2 = global { i32, i32 } { i32 1, i32 10 }
|
2009-01-29 14:43:41 +08:00
|
|
|
_Complex int g2 = 1 + 10i;
|
2011-07-10 01:41:47 +08:00
|
|
|
// CHECK: @g3 = global { float, float } { float 1.000000e+00{{[0]*}}, float 1.000000e+0{{[0]*}}1 }
|
2009-01-29 14:43:41 +08:00
|
|
|
_Complex float g3 = 1.0 + 10.0i;
|
2011-07-10 01:41:47 +08:00
|
|
|
// CHECK: @g4 = global { double, double } { double 1.000000e+00{{[0]*}}, double 1.000000e+0{{[0]*}}1 }
|
2009-01-29 14:43:41 +08:00
|
|
|
_Complex double g4 = 1.0 + 10.0i;
|
2011-07-10 01:41:47 +08:00
|
|
|
// CHECK: @g5 = global { i32, i32 } zeroinitializer
|
2009-01-29 14:43:41 +08:00
|
|
|
_Complex int g5 = (2 + 3i) == (5 + 7i);
|
2011-07-10 01:41:47 +08:00
|
|
|
// CHECK: @g6 = global { double, double } { double -1.100000e+0{{[0]*}}1, double 2.900000e+0{{[0]*}}1 }
|
2009-01-29 14:43:41 +08:00
|
|
|
_Complex double g6 = (2.0 + 3.0i) * (5.0 + 7.0i);
|
2009-10-02 18:32:51 +08:00
|
|
|
// CHECK: @g7 = global i32 1
|
2009-01-29 14:43:41 +08:00
|
|
|
int g7 = (2 + 3i) * (5 + 7i) == (-11 + 29i);
|
2009-10-02 18:32:51 +08:00
|
|
|
// CHECK: @g8 = global i32 1
|
2009-01-29 14:43:41 +08:00
|
|
|
int g8 = (2.0 + 3.0i) * (5.0 + 7.0i) == (-11.0 + 29.0i);
|
2009-10-02 18:32:51 +08:00
|
|
|
// CHECK: @g9 = global i32 0
|
2009-01-29 14:43:41 +08:00
|
|
|
int g9 = (2 + 3i) * (5 + 7i) != (-11 + 29i);
|
2009-10-02 18:32:51 +08:00
|
|
|
// CHECK: @g10 = global i32 0
|
2009-01-29 14:43:41 +08:00
|
|
|
int g10 = (2.0 + 3.0i) * (5.0 + 7.0i) != (-11.0 + 29.0i);
|
|
|
|
|
2009-10-02 10:15:20 +08:00
|
|
|
// PR5108
|
2011-07-12 13:53:08 +08:00
|
|
|
// CHECK: @gv1 = global %struct.anon <{ i32 0, i8 7 }>, align 1
|
2009-10-02 12:52:12 +08:00
|
|
|
struct {
|
2009-10-02 10:15:20 +08:00
|
|
|
unsigned long a;
|
|
|
|
unsigned long b:3;
|
2009-10-02 12:52:12 +08:00
|
|
|
} __attribute__((__packed__)) gv1 = { .a = 0x0, .b = 7, };
|
|
|
|
|
|
|
|
// PR5118
|
2011-07-12 13:53:08 +08:00
|
|
|
// CHECK: @gv2 = global %struct.anon.0 <{ i8 1, i8* null }>, align 1
|
2009-10-02 12:52:12 +08:00
|
|
|
struct {
|
|
|
|
unsigned char a;
|
|
|
|
char *b;
|
|
|
|
} __attribute__((__packed__)) gv2 = { 1, (void*)0 };
|
2009-01-29 14:43:41 +08:00
|
|
|
|
2009-02-20 06:24:01 +08:00
|
|
|
// Global references
|
2009-10-02 18:32:51 +08:00
|
|
|
// CHECK: @g11.l0 = internal global i32 ptrtoint (i32 ()* @g11 to i32)
|
2009-02-20 06:24:01 +08:00
|
|
|
long g11() {
|
|
|
|
static long l0 = (long) g11;
|
|
|
|
return l0;
|
|
|
|
}
|
|
|
|
|
2009-10-02 18:32:51 +08:00
|
|
|
// CHECK: @g12 = global i32 ptrtoint (i8* @g12_tmp to i32)
|
2009-02-20 06:24:01 +08:00
|
|
|
static char g12_tmp;
|
|
|
|
long g12 = (long) &g12_tmp;
|
|
|
|
|
2009-10-02 18:32:51 +08:00
|
|
|
// CHECK: @g13 = global [1 x %struct.g13_s0] [%struct.g13_s0 { i32 ptrtoint (i8* @g12_tmp to i32) }]
|
2009-02-20 06:24:01 +08:00
|
|
|
struct g13_s0 {
|
|
|
|
long a;
|
|
|
|
};
|
|
|
|
struct g13_s0 g13[] = {
|
|
|
|
{ (long) &g12_tmp }
|
|
|
|
};
|
|
|
|
|
2009-10-02 18:32:51 +08:00
|
|
|
// CHECK: @g14 = global i8* inttoptr (i64 100 to i8*)
|
2009-02-20 06:24:01 +08:00
|
|
|
void *g14 = (void*) 100;
|
|
|
|
|
2009-10-02 18:32:51 +08:00
|
|
|
// CHECK: @g15 = global i32 -1
|
2009-02-20 06:24:01 +08:00
|
|
|
int g15 = (int) (char) ((void*) 0 + 255);
|
|
|
|
|
2009-10-02 18:32:51 +08:00
|
|
|
// CHECK: @g16 = global i64 4294967295
|
2009-02-20 06:24:01 +08:00
|
|
|
long long g16 = (long long) ((void*) 0xFFFFFFFF);
|
|
|
|
|
2009-10-02 18:32:51 +08:00
|
|
|
// CHECK: @g17 = global i32* @g15
|
2009-02-21 02:22:23 +08:00
|
|
|
int *g17 = (int *) ((long) &g15);
|
|
|
|
|
2009-10-02 18:32:51 +08:00
|
|
|
// CHECK: @g18.p = internal global [1 x i32*] [i32* @g19]
|
2009-02-25 02:41:57 +08:00
|
|
|
void g18(void) {
|
|
|
|
extern int g19;
|
|
|
|
static int *p[] = { &g19 };
|
|
|
|
}
|
|
|
|
|
2009-10-02 18:32:51 +08:00
|
|
|
// 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) }
|
2009-02-26 04:08:33 +08:00
|
|
|
struct g20_s0;
|
|
|
|
struct g20_s1 {
|
|
|
|
struct g20_s0 *f0, **f1;
|
|
|
|
};
|
|
|
|
void *g20(void) {
|
|
|
|
static struct g20_s1 l0 = { ((void*) 0), &l0.f0 };
|
|
|
|
return l0.f1;
|
|
|
|
}
|
|
|
|
|
2009-04-30 15:03:22 +08:00
|
|
|
// PR4108
|
|
|
|
struct g21 {int g21;};
|
|
|
|
const struct g21 g21 = (struct g21){1};
|
2009-11-14 05:23:46 +08:00
|
|
|
|
|
|
|
// PR5474
|
|
|
|
struct g22 {int x;} __attribute((packed));
|
|
|
|
struct g23 {char a; short b; char c; struct g22 d;};
|
|
|
|
struct g23 g24 = {1,2,3,4};
|
|
|
|
|
2009-11-14 16:37:13 +08:00
|
|
|
// CHECK: @g25.g26 = internal global i8* getelementptr inbounds ([4 x i8]* @__func__.g25, i32 0, i32 0)
|
2011-01-11 06:34:03 +08:00
|
|
|
// CHECK: @__func__.g25 = private unnamed_addr constant [4 x i8] c"g25\00"
|
2009-11-14 16:37:13 +08:00
|
|
|
int g25() {
|
|
|
|
static const char *g26 = __func__;
|
|
|
|
return *g26;
|
|
|
|
}
|
2010-09-04 02:58:50 +08:00
|
|
|
|
|
|
|
// CHECK: @g27.x = internal global i8* bitcast (i8** @g27.x to i8*), align 4
|
|
|
|
void g27() { // PR8073
|
|
|
|
static void *x = &x;
|
|
|
|
}
|
2011-12-22 11:51:45 +08:00
|
|
|
|
|
|
|
void g28() {
|
|
|
|
typedef long long v1i64 __attribute((vector_size(8)));
|
|
|
|
typedef short v12i16 __attribute((vector_size(24)));
|
|
|
|
typedef long double v2f80 __attribute((vector_size(24)));
|
|
|
|
// CHECK: @g28.a = internal global <1 x i64> <i64 10>
|
|
|
|
// 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>
|
|
|
|
// CHECK: @g28.c = internal global <2 x x86_fp80> <x86_fp80 0xK3FFF8000000000000000, x86_fp80 0xK40008000000000000000>, align 32
|
|
|
|
static v1i64 a = (v1i64)10LL;
|
|
|
|
static v12i16 b = (v2f80){1,2};
|
|
|
|
static v2f80 c = (v12i16){0,0,0,-32768,16383,0,0,0,0,-32768,16384,0};
|
|
|
|
}
|