2018-04-05 23:29:52 +08:00
|
|
|
// RUN: %clang_cc1 -w -fmerge-all-constants -emit-llvm < %s | FileCheck %s
|
2009-12-05 14:49:57 +08:00
|
|
|
|
2011-03-07 07:28:21 +08:00
|
|
|
// CHECK: @test1.x = internal constant [12 x i32] [i32 1
|
2018-11-15 08:19:18 +08:00
|
|
|
// CHECK: @__const.test2.x = private unnamed_addr constant [13 x i32] [i32 1,
|
2018-02-24 03:30:48 +08:00
|
|
|
// CHECK: @test5w = {{(dso_local )?}}global { i32, [4 x i8] } { i32 2, [4 x i8] undef }
|
|
|
|
// CHECK: @test5y = {{(dso_local )?}}global { double } { double 7.300000e+0{{[0]*}}1 }
|
2009-12-05 16:22:11 +08:00
|
|
|
|
2018-11-15 08:19:18 +08:00
|
|
|
// CHECK: @__const.test6.x = private unnamed_addr constant %struct.SelectDest { i8 1, i8 2, i32 3, i32 0 }
|
Rework the ConstStructBuilder code to emit missing initializer
elements with explicit zero values instead of with tail padding.
On an example like this:
struct foo { int a; int b; };
struct foo fooarray[] = {
{1, 2},
{4},
};
We now lay this out as:
@fooarray = global [2 x %struct.foo] [%struct.foo { i32 1, i32 2 }, %struct.foo { i32 4, i32 0 }]
instead of as:
@fooarray = global %0 <{ %struct.foo { i32 1, i32 2 }, %1 { i32 4, [4 x i8] zeroinitializer } }>
Preserving both the struct type of the second element, but also the array type of the entire thing.
llvm-svn: 101155
2010-04-14 02:16:19 +08:00
|
|
|
|
2018-02-24 03:30:48 +08:00
|
|
|
// CHECK: @test7 = {{(dso_local )?}}global [2 x %struct.test7s] [%struct.test7s { i32 1, i32 2 }, %struct.test7s { i32 4, i32 0 }]
|
Rework the ConstStructBuilder code to emit missing initializer
elements with explicit zero values instead of with tail padding.
On an example like this:
struct foo { int a; int b; };
struct foo fooarray[] = {
{1, 2},
{4},
};
We now lay this out as:
@fooarray = global [2 x %struct.foo] [%struct.foo { i32 1, i32 2 }, %struct.foo { i32 4, i32 0 }]
instead of as:
@fooarray = global %0 <{ %struct.foo { i32 1, i32 2 }, %1 { i32 4, [4 x i8] zeroinitializer } }>
Preserving both the struct type of the second element, but also the array type of the entire thing.
llvm-svn: 101155
2010-04-14 02:16:19 +08:00
|
|
|
|
2009-12-05 14:49:57 +08:00
|
|
|
void test1() {
|
|
|
|
// This should codegen as a "@test1.x" global.
|
|
|
|
const int x[] = { 1, 2, 3, 4, 6, 8, 9, 10, 123, 231, 123,23 };
|
|
|
|
foo(x);
|
|
|
|
|
|
|
|
// CHECK: @test1()
|
|
|
|
// CHECK: {{call.*@foo.*@test1.x}}
|
|
|
|
}
|
2009-12-05 16:22:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
// rdar://7346691
|
|
|
|
void test2() {
|
|
|
|
// This should codegen as a "@test2.x" global + memcpy.
|
|
|
|
int x[] = { 1, 2, 3, 4, 6, 8, 9, 10, 123, 231, 123,23, 24 };
|
|
|
|
foo(x);
|
2011-08-24 08:33:55 +08:00
|
|
|
|
2009-12-05 16:22:11 +08:00
|
|
|
// CHECK: @test2()
|
|
|
|
// CHECK: %x = alloca [13 x i32]
|
|
|
|
// CHECK: call void @llvm.memcpy
|
|
|
|
// CHECK: call{{.*}}@foo{{.*}}i32* %
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void test3() {
|
2009-12-05 16:33:21 +08:00
|
|
|
// This should codegen as a memset.
|
2009-12-05 16:22:11 +08:00
|
|
|
int x[100] = { 0 };
|
|
|
|
foo(x);
|
2011-08-24 08:33:55 +08:00
|
|
|
|
2009-12-05 16:22:11 +08:00
|
|
|
// CHECK: @test3()
|
|
|
|
// CHECK: %x = alloca [100 x i32]
|
|
|
|
// CHECK: call void @llvm.memset
|
|
|
|
}
|
|
|
|
|
2009-12-05 16:30:04 +08:00
|
|
|
void test4(void) {
|
|
|
|
char a[10] = "asdf";
|
|
|
|
char b[10] = { "asdf" };
|
|
|
|
// CHECK: @test4()
|
|
|
|
// CHECK: %a = alloca [10 x i8]
|
|
|
|
// CHECK: %b = alloca [10 x i8]
|
|
|
|
// CHECK: call void @llvm.memcpy
|
|
|
|
// CHECK: call void @llvm.memcpy
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
union test5u { int i; double d; };
|
|
|
|
|
|
|
|
void test5() {
|
|
|
|
union test5u ola = (union test5u) 351;
|
|
|
|
union test5u olb = (union test5u) 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
union test5u test5w = (union test5u)2;
|
|
|
|
union test5u test5y = (union test5u)73.0;
|
|
|
|
|
2010-04-13 05:10:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
// PR6660 - sqlite miscompile
|
|
|
|
struct SelectDest {
|
|
|
|
unsigned char eDest;
|
|
|
|
unsigned char affinity;
|
|
|
|
int iParm;
|
|
|
|
int iMem;
|
|
|
|
};
|
|
|
|
|
|
|
|
void test6() {
|
|
|
|
struct SelectDest x = {1, 2, 3};
|
|
|
|
test6f(&x);
|
|
|
|
}
|
Rework the ConstStructBuilder code to emit missing initializer
elements with explicit zero values instead of with tail padding.
On an example like this:
struct foo { int a; int b; };
struct foo fooarray[] = {
{1, 2},
{4},
};
We now lay this out as:
@fooarray = global [2 x %struct.foo] [%struct.foo { i32 1, i32 2 }, %struct.foo { i32 4, i32 0 }]
instead of as:
@fooarray = global %0 <{ %struct.foo { i32 1, i32 2 }, %1 { i32 4, [4 x i8] zeroinitializer } }>
Preserving both the struct type of the second element, but also the array type of the entire thing.
llvm-svn: 101155
2010-04-14 02:16:19 +08:00
|
|
|
|
|
|
|
// rdar://7657600
|
|
|
|
struct test7s { int a; int b; } test7[] = {
|
|
|
|
{1, 2},
|
|
|
|
{4},
|
|
|
|
};
|
|
|
|
|
2010-04-17 05:02:32 +08:00
|
|
|
// rdar://7872531
|
|
|
|
#pragma pack(push, 2)
|
|
|
|
struct test8s { int f0; char f1; } test8g = {};
|
|
|
|
|
|
|
|
|
2010-07-01 03:14:05 +08:00
|
|
|
// PR7519
|
|
|
|
|
|
|
|
struct S {
|
|
|
|
void (*x) (struct S *);
|
|
|
|
};
|
|
|
|
|
|
|
|
extern struct S *global_dc;
|
|
|
|
void cp_diagnostic_starter(struct S *);
|
|
|
|
|
|
|
|
void init_error(void) {
|
|
|
|
global_dc->x = cp_diagnostic_starter;
|
|
|
|
}
|
|
|
|
|
2010-07-01 14:20:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
// rdar://8147692 - ABI crash in recursive struct-through-function-pointer.
|
|
|
|
typedef struct {
|
|
|
|
int x5a;
|
|
|
|
} x5;
|
|
|
|
|
|
|
|
typedef struct x2 *x0;
|
|
|
|
typedef long (*x1)(x0 x0a, x5 x6);
|
|
|
|
struct x2 {
|
|
|
|
x1 x4;
|
|
|
|
};
|
|
|
|
long x3(x0 x0a, x5 a) {
|
|
|
|
return x0a->x4(x0a, a);
|
|
|
|
}
|