2014-06-30 17:05:08 +08:00
|
|
|
// RUN: %clang_cc1 -fblocks -emit-llvm %s -o %t
|
2013-05-10 03:17:11 +08:00
|
|
|
// RUN: FileCheck %s -input-file=%t -check-prefix=CHECK1
|
|
|
|
// RUN: FileCheck %s -input-file=%t -check-prefix=CHECK2
|
|
|
|
|
|
|
|
struct A {
|
2014-06-30 17:05:08 +08:00
|
|
|
int a;
|
2013-05-10 03:17:11 +08:00
|
|
|
float b;
|
|
|
|
char c;
|
|
|
|
};
|
|
|
|
|
2014-06-30 17:05:08 +08:00
|
|
|
void test_nest_captured_stmt(int param, int size, int param_arr[size]) {
|
2013-05-10 03:17:11 +08:00
|
|
|
int w;
|
2014-06-30 10:55:54 +08:00
|
|
|
int arr[param][size];
|
2014-10-29 20:21:55 +08:00
|
|
|
// CHECK1: %struct.anon{{.*}} = type { [[INT:i.+]]*, [[INT]]*, [[SIZE_TYPE:i.+]], [[INT]]**, [[INT]]*, [[SIZE_TYPE]], [[SIZE_TYPE]], [[INT]]* }
|
|
|
|
// CHECK1: %struct.anon{{.*}} = type { [[INT]]*, [[INT]]*, [[INT]]**, [[INT]]*, [[SIZE_TYPE]], [[INT]]**, [[INT]]*, [[SIZE_TYPE]], [[SIZE_TYPE]], [[INT]]* }
|
|
|
|
// CHECK1: [[T:%struct.anon.*]] = type { [[INT]]*, [[INT]]*, %struct.A*, [[INT]]**, [[INT]]*, [[SIZE_TYPE]], [[INT]]**, [[INT]]*, [[SIZE_TYPE]], [[SIZE_TYPE]], [[INT]]* }
|
2013-05-10 03:17:11 +08:00
|
|
|
#pragma clang __debug captured
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int *y = &w;
|
|
|
|
#pragma clang __debug captured
|
|
|
|
{
|
|
|
|
struct A z;
|
|
|
|
#pragma clang __debug captured
|
|
|
|
{
|
|
|
|
w = x = z.a = 1;
|
|
|
|
*y = param;
|
|
|
|
z.b = 0.1f;
|
|
|
|
z.c = 'c';
|
2014-06-30 10:55:54 +08:00
|
|
|
param_arr[size - 1] = 2;
|
|
|
|
arr[10][z.a] = 12;
|
2013-05-10 03:17:11 +08:00
|
|
|
|
|
|
|
// CHECK1: define internal void @__captured_stmt{{.*}}([[T]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK1: [[PARAM_ARR_SIZE_REF:%.+]] = getelementptr inbounds [[T]], [[T]]* {{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 5
|
2014-10-29 20:21:55 +08:00
|
|
|
// CHECK1: [[PARAM_ARR_SIZE:%.+]] = load [[SIZE_TYPE]]* [[PARAM_ARR_SIZE_REF]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK1: [[ARR_SIZE1_REF:%.+]] = getelementptr inbounds [[T]], [[T]]* {{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 8
|
2014-10-29 20:21:55 +08:00
|
|
|
// CHECK1: [[ARR_SIZE1:%.+]] = load [[SIZE_TYPE]]* [[ARR_SIZE1_REF]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK1: [[ARR_SIZE2_REF:%.+]] = getelementptr inbounds [[T]], [[T]]* {{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 9
|
2014-10-29 20:21:55 +08:00
|
|
|
// CHECK1: [[ARR_SIZE2:%.+]] = load [[SIZE_TYPE]]* [[ARR_SIZE2_REF]]
|
2013-05-10 03:17:11 +08:00
|
|
|
//
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK1: getelementptr inbounds [[T]], [[T]]* {{.*}}, i{{[0-9]+}} 0, i{{[0-9]+}} 2
|
2013-05-10 03:17:11 +08:00
|
|
|
// CHECK1-NEXT: load %struct.A**
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK1-NEXT: getelementptr inbounds %struct.A, %struct.A*
|
2014-06-30 16:17:11 +08:00
|
|
|
// CHECK1-NEXT: store i{{.+}} 1
|
2013-05-10 03:17:11 +08:00
|
|
|
//
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK1: getelementptr inbounds [[T]], [[T]]* {{.*}}, i{{[0-9]+}} 0, i{{[0-9]+}} 1
|
2014-10-29 20:21:55 +08:00
|
|
|
// CHECK1-NEXT: load i{{[0-9]+}}**
|
|
|
|
// CHECK1-NEXT: store i{{[0-9]+}} 1
|
2013-05-10 03:17:11 +08:00
|
|
|
//
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK1: getelementptr inbounds [[T]], [[T]]* {{.*}}, i{{[0-9]+}} 0, i{{[0-9]+}} 0
|
2014-10-29 20:21:55 +08:00
|
|
|
// CHECK1-NEXT: load i{{[0-9]+}}**
|
|
|
|
// CHECK1-NEXT: store i{{[0-9]+}} 1
|
2013-05-10 03:17:11 +08:00
|
|
|
//
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK1: getelementptr inbounds [[T]], [[T]]* {{.*}}, i{{[0-9]+}} 0, i{{[0-9]+}} 4
|
2014-10-29 20:21:55 +08:00
|
|
|
// CHECK1-NEXT: load i{{[0-9]+}}**
|
|
|
|
// CHECK1-NEXT: load i{{[0-9]+}}*
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK1-NEXT: getelementptr inbounds [[T]], [[T]]* {{.*}}, i{{[0-9]+}} 0, i{{[0-9]+}} 3
|
2014-10-29 20:21:55 +08:00
|
|
|
// CHECK1-NEXT: load i{{[0-9]+}}***
|
|
|
|
// CHECK1-NEXT: load i{{[0-9]+}}**
|
|
|
|
// CHECK1-NEXT: store i{{[0-9]+}}
|
2013-05-10 03:17:11 +08:00
|
|
|
//
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK1: getelementptr inbounds [[T]], [[T]]* {{.*}}, i{{[0-9]+}} 0, i{{[0-9]+}} 2
|
2013-05-10 03:17:11 +08:00
|
|
|
// CHECK1-NEXT: load %struct.A**
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK1-NEXT: getelementptr inbounds %struct.A, %struct.A*
|
2013-05-10 03:17:11 +08:00
|
|
|
// CHECK1-NEXT: store float
|
|
|
|
//
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK1: getelementptr inbounds [[T]], [[T]]* {{.*}}, i{{[0-9]+}} 0, i{{[0-9]+}} 2
|
2013-05-10 03:17:11 +08:00
|
|
|
// CHECK1-NEXT: load %struct.A**
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK1-NEXT: getelementptr inbounds %struct.A, %struct.A*
|
2013-05-10 03:17:11 +08:00
|
|
|
// CHECK1-NEXT: store i8 99
|
2014-06-30 10:55:54 +08:00
|
|
|
//
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK1: [[SIZE_ADDR_REF:%.*]] = getelementptr inbounds [[T]], [[T]]* {{.*}}, i{{.+}} 0, i{{.+}} 7
|
2014-06-30 16:17:11 +08:00
|
|
|
// CHECK1-DAG: [[SIZE_ADDR:%.*]] = load i{{.+}}** [[SIZE_ADDR_REF]]
|
|
|
|
// CHECK1-DAG: [[SIZE:%.*]] = load i{{.+}}* [[SIZE_ADDR]]
|
|
|
|
// CHECK1-DAG: [[PARAM_ARR_IDX:%.*]] = sub nsw i{{.+}} [[SIZE]], 1
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK1-DAG: [[PARAM_ARR_ADDR_REF:%.*]] = getelementptr inbounds [[T]], [[T]]* {{.*}}, i{{.+}} 0, i{{.+}} 6
|
2014-06-30 16:17:11 +08:00
|
|
|
// CHECK1-DAG: [[PARAM_ARR_ADDR:%.*]] = load i{{.+}}*** [[PARAM_ARR_ADDR_REF]]
|
|
|
|
// CHECK1-DAG: [[PARAM_ARR:%.*]] = load i{{.+}}** [[PARAM_ARR_ADDR]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK1-DAG: [[PARAM_ARR_SIZE_MINUS_1_ADDR:%.*]] = getelementptr inbounds i{{.+}}, i{{.+}}* [[PARAM_ARR]], i{{.*}}
|
2014-06-30 16:17:11 +08:00
|
|
|
// CHECK1: store i{{.+}} 2, i{{.+}}* [[PARAM_ARR_SIZE_MINUS_1_ADDR]]
|
2014-06-30 10:55:54 +08:00
|
|
|
//
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK1: [[Z_ADDR_REF:%.*]] = getelementptr inbounds [[T]], [[T]]* {{.*}}, i{{.+}} 0, i{{.+}} 2
|
2014-06-30 13:02:50 +08:00
|
|
|
// CHECK1-DAG: [[Z_ADDR:%.*]] = load %struct.A** [[Z_ADDR_REF]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK1-DAG: [[Z_A_ADDR:%.*]] = getelementptr inbounds %struct.A, %struct.A* [[Z_ADDR]], i{{.+}} 0, i{{.+}} 0
|
2014-06-30 16:17:11 +08:00
|
|
|
// CHECK1-DAG: [[ARR_IDX_2:%.*]] = load i{{.+}}* [[Z_A_ADDR]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK1-DAG: [[ARR_ADDR_REF:%.*]] = getelementptr inbounds [[T]], [[T]]* {{.*}}, i{{.+}} 0, i{{.+}} 10
|
2014-06-30 16:17:11 +08:00
|
|
|
// CHECK1-DAG: [[ARR_ADDR:%.*]] = load i{{.+}}** [[ARR_ADDR_REF]]
|
2014-06-30 13:02:50 +08:00
|
|
|
// CHECK1-DAG: [[ARR_IDX_1:%.*]] = mul {{.*}} 10
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK1-DAG: [[ARR_10_ADDR:%.*]] = getelementptr inbounds i{{.+}}, i{{.+}}* [[ARR_ADDR]], i{{.*}} [[ARR_IDX_1]]
|
|
|
|
// CHECK1-DAG: [[ARR_10_Z_A_ADDR:%.*]] = getelementptr inbounds i{{.+}}, i{{.+}}* [[ARR_10_ADDR]], i{{.*}}
|
2014-06-30 16:17:11 +08:00
|
|
|
// CHECK1: store i{{.+}} 12, i{{.+}}* [[ARR_10_Z_A_ADDR]]
|
2013-05-10 03:17:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_nest_block() {
|
|
|
|
__block int x;
|
|
|
|
int y;
|
|
|
|
^{
|
|
|
|
int z;
|
|
|
|
x = z;
|
|
|
|
#pragma clang __debug captured
|
|
|
|
{
|
|
|
|
z = y; // OK
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
|
|
|
|
// CHECK2: define internal void @{{.*}}test_nest_block_block_invoke
|
|
|
|
//
|
2014-10-29 21:21:52 +08:00
|
|
|
// CHECK2: [[Z:%[0-9a-z_]*]] = alloca i{{[0-9]+}},
|
2013-05-10 03:17:11 +08:00
|
|
|
// CHECK2: alloca %struct.anon{{.*}}
|
|
|
|
//
|
2014-10-29 20:21:55 +08:00
|
|
|
// CHECK2: store i{{[0-9]+}}
|
|
|
|
// CHECK2: store i{{[0-9]+}}* [[Z]]
|
2013-05-10 03:17:11 +08:00
|
|
|
//
|
|
|
|
// CHECK2: getelementptr inbounds %struct.anon
|
|
|
|
// CHECK2-NEXT: getelementptr inbounds
|
2014-10-29 20:21:55 +08:00
|
|
|
// CHECK2-NEXT: store i{{[0-9]+}}*
|
2013-05-10 03:17:11 +08:00
|
|
|
//
|
|
|
|
// CHECK2: call void @__captured_stmt
|
|
|
|
|
|
|
|
int a;
|
|
|
|
#pragma clang __debug captured
|
|
|
|
{
|
|
|
|
__block int b;
|
|
|
|
int c;
|
|
|
|
__block int d;
|
|
|
|
^{
|
|
|
|
b = a;
|
|
|
|
b = c;
|
|
|
|
b = d;
|
|
|
|
}();
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK2: alloca %struct.__block_byref_b
|
2014-10-29 20:21:55 +08:00
|
|
|
// CHECK2-NEXT: [[C:%[0-9a-z_]*]] = alloca i{{[0-9]+}}
|
2013-05-10 03:17:11 +08:00
|
|
|
// CHECK2-NEXT: alloca %struct.__block_byref_d
|
|
|
|
//
|
|
|
|
// CHECK2: bitcast %struct.__block_byref_b*
|
|
|
|
// CHECK2-NEXT: store i8*
|
|
|
|
//
|
2014-10-29 20:21:55 +08:00
|
|
|
// CHECK2: [[CapA:%[0-9a-z_.]*]] = getelementptr inbounds {{.*}}, i{{[0-9]+}} 0, i{{[0-9]+}} 7
|
2013-05-10 03:17:11 +08:00
|
|
|
//
|
2014-10-29 20:21:55 +08:00
|
|
|
// CHECK2: getelementptr inbounds %struct.anon{{.*}}, i{{[0-9]+}} 0, i{{[0-9]+}} 0
|
|
|
|
// CHECK2: load i{{[0-9]+}}**
|
|
|
|
// CHECK2: load i{{[0-9]+}}*
|
|
|
|
// CHECK2: store i{{[0-9]+}} {{.*}}, i{{[0-9]+}}* [[CapA]]
|
2013-05-10 03:17:11 +08:00
|
|
|
//
|
2014-10-29 20:21:55 +08:00
|
|
|
// CHECK2: [[CapC:%[0-9a-z_.]*]] = getelementptr inbounds {{.*}}, i{{[0-9]+}} 0, i{{[0-9]+}} 8
|
|
|
|
// CHECK2-NEXT: [[Val:%[0-9a-z_]*]] = load i{{[0-9]+}}* [[C]]
|
|
|
|
// CHECK2-NEXT: store i{{[0-9]+}} [[Val]], i{{[0-9]+}}* [[CapC]]
|
2013-05-10 03:17:11 +08:00
|
|
|
//
|
|
|
|
// CHECK2: bitcast %struct.__block_byref_d*
|
|
|
|
// CHECK2-NEXT: store i8*
|
|
|
|
}
|