2010-04-19 03:06:43 +08:00
|
|
|
// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck %s
|
2009-02-14 06:58:39 +08:00
|
|
|
|
2008-02-19 06:44:02 +08:00
|
|
|
void f1() {
|
|
|
|
// Scalars in braces.
|
|
|
|
int a = { 1 };
|
|
|
|
}
|
|
|
|
|
|
|
|
void f2() {
|
|
|
|
int a[2][2] = { { 1, 2 }, { 3, 4 } };
|
|
|
|
int b[3][3] = { { 1, 2 }, { 3, 4 } };
|
|
|
|
int *c[2] = { &a[1][1], &b[2][2] };
|
|
|
|
int *d[2][2] = { {&a[1][1], &b[2][2]}, {&a[0][0], &b[1][1]} };
|
|
|
|
int *e[3][3] = { {&a[1][1], &b[2][2]}, {&a[0][0], &b[1][1]} };
|
2008-02-20 03:27:31 +08:00
|
|
|
char ext[3][3] = {".Y",".U",".V"};
|
2008-01-29 09:28:48 +08:00
|
|
|
}
|
2008-05-04 08:56:25 +08:00
|
|
|
|
|
|
|
typedef void (* F)(void);
|
|
|
|
extern void foo(void);
|
|
|
|
struct S { F f; };
|
|
|
|
void f3() {
|
|
|
|
struct S a[1] = { { foo } };
|
|
|
|
}
|
|
|
|
|
2009-02-14 06:58:39 +08:00
|
|
|
// Constants
|
2010-04-19 03:06:43 +08:00
|
|
|
// CHECK: @g3 = constant i32 10
|
|
|
|
// CHECK: @f4.g4 = internal constant i32 12
|
2009-02-14 06:58:39 +08:00
|
|
|
const int g3 = 10;
|
|
|
|
int f4() {
|
|
|
|
static const int g4 = 12;
|
|
|
|
return g4;
|
|
|
|
}
|
2010-03-09 05:08:07 +08:00
|
|
|
|
|
|
|
// PR6537
|
|
|
|
typedef union vec3 {
|
|
|
|
struct { double x, y, z; };
|
|
|
|
double component[3];
|
|
|
|
} vec3;
|
|
|
|
vec3 f5(vec3 value) {
|
|
|
|
return (vec3) {{
|
|
|
|
.x = value.x
|
|
|
|
}};
|
|
|
|
}
|
2010-07-07 13:08:32 +08:00
|
|
|
|
|
|
|
// rdar://problem/8154689
|
|
|
|
void f6() {
|
|
|
|
int x;
|
|
|
|
long ids[] = { (long) &x };
|
|
|
|
}
|
2010-10-11 01:49:49 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// CHECK: @test7 = global{{.*}}{ i32 0, [4 x i8] c"bar\00" }
|
|
|
|
// PR8217
|
|
|
|
struct a7 {
|
|
|
|
int b;
|
|
|
|
char v[];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct a7 test7 = { .b = 0, .v = "bar" };
|
Enhance the init generation logic to emit a memset followed by a few stores when
a global is larger than 32 bytes and has fewer than 6 non-zero values in the
initializer. Previously we'd turn something like this:
char test8(int X) {
char str[10000] = "abc";
into a 10K global variable which we then memcpy'd from. Now we generate:
%str = alloca [10000 x i8], align 16
%tmp = getelementptr inbounds [10000 x i8]* %str, i64 0, i64 0
call void @llvm.memset.p0i8.i64(i8* %tmp, i8 0, i64 10000, i32 16, i1 false)
store i8 97, i8* %tmp, align 16
%0 = getelementptr [10000 x i8]* %str, i64 0, i64 1
store i8 98, i8* %0, align 1
%1 = getelementptr [10000 x i8]* %str, i64 0, i64 2
store i8 99, i8* %1, align 2
Which is much smaller in space and also likely faster.
This is part of PR279
llvm-svn: 120645
2010-12-02 09:58:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
// PR279 comment #3
|
|
|
|
char test8(int X) {
|
|
|
|
char str[100000] = "abc"; // tail should be memset.
|
|
|
|
return str[X];
|
|
|
|
// CHECK: @test8(
|
|
|
|
// CHECK: call void @llvm.memset
|
|
|
|
// CHECK: store i8 97
|
|
|
|
// CHECK: store i8 98
|
|
|
|
// CHECK: store i8 99
|
|
|
|
}
|