1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fblocks -emit-llvm %s -o %t 2*f4a2713aSLionel Sambuc // RUN: FileCheck %s -input-file=%t -check-prefix=CHECK1 3*f4a2713aSLionel Sambuc // RUN: FileCheck %s -input-file=%t -check-prefix=CHECK2 4*f4a2713aSLionel Sambuc 5*f4a2713aSLionel Sambuc struct A { 6*f4a2713aSLionel Sambuc int a; 7*f4a2713aSLionel Sambuc float b; 8*f4a2713aSLionel Sambuc char c; 9*f4a2713aSLionel Sambuc }; 10*f4a2713aSLionel Sambuc 11*f4a2713aSLionel Sambuc void test_nest_captured_stmt(int param) { 12*f4a2713aSLionel Sambuc int w; 13*f4a2713aSLionel Sambuc // CHECK1: %struct.anon{{.*}} = type { i32*, i32* } 14*f4a2713aSLionel Sambuc // CHECK1: %struct.anon{{.*}} = type { i32*, i32*, i32**, i32* } 15*f4a2713aSLionel Sambuc // CHECK1: [[T:%struct.anon.*]] = type { i32*, i32*, %struct.A*, i32**, i32* } 16*f4a2713aSLionel Sambuc #pragma clang __debug captured 17*f4a2713aSLionel Sambuc { 18*f4a2713aSLionel Sambuc int x; 19*f4a2713aSLionel Sambuc int *y = &w; 20*f4a2713aSLionel Sambuc #pragma clang __debug captured 21*f4a2713aSLionel Sambuc { 22*f4a2713aSLionel Sambuc struct A z; 23*f4a2713aSLionel Sambuc #pragma clang __debug captured 24*f4a2713aSLionel Sambuc { 25*f4a2713aSLionel Sambuc w = x = z.a = 1; 26*f4a2713aSLionel Sambuc *y = param; 27*f4a2713aSLionel Sambuc z.b = 0.1f; 28*f4a2713aSLionel Sambuc z.c = 'c'; 29*f4a2713aSLionel Sambuc 30*f4a2713aSLionel Sambuc // CHECK1: define internal void @__captured_stmt{{.*}}([[T]] 31*f4a2713aSLionel Sambuc // 32*f4a2713aSLionel Sambuc // CHECK1: getelementptr inbounds [[T]]* {{.*}}, i32 0, i32 2 33*f4a2713aSLionel Sambuc // CHECK1-NEXT: load %struct.A** 34*f4a2713aSLionel Sambuc // CHECK1-NEXT: getelementptr inbounds %struct.A* 35*f4a2713aSLionel Sambuc // CHECK1-NEXT: store i32 1 36*f4a2713aSLionel Sambuc // 37*f4a2713aSLionel Sambuc // CHECK1: getelementptr inbounds [[T]]* {{.*}}, i32 0, i32 1 38*f4a2713aSLionel Sambuc // CHECK1-NEXT: load i32** 39*f4a2713aSLionel Sambuc // CHECK1-NEXT: store i32 1 40*f4a2713aSLionel Sambuc // 41*f4a2713aSLionel Sambuc // CHECK1: getelementptr inbounds [[T]]* {{.*}}, i32 0, i32 0 42*f4a2713aSLionel Sambuc // CHECK1-NEXT: load i32** 43*f4a2713aSLionel Sambuc // CHECK1-NEXT: store i32 1 44*f4a2713aSLionel Sambuc // 45*f4a2713aSLionel Sambuc // CHECK1: getelementptr inbounds [[T]]* {{.*}}, i32 0, i32 4 46*f4a2713aSLionel Sambuc // CHECK1-NEXT: load i32** 47*f4a2713aSLionel Sambuc // CHECK1-NEXT: load i32* 48*f4a2713aSLionel Sambuc // CHECK1-NEXT: getelementptr inbounds [[T]]* {{.*}}, i32 0, i32 3 49*f4a2713aSLionel Sambuc // CHECK1-NEXT: load i32*** 50*f4a2713aSLionel Sambuc // CHECK1-NEXT: load i32** 51*f4a2713aSLionel Sambuc // CHECK1-NEXT: store i32 52*f4a2713aSLionel Sambuc // 53*f4a2713aSLionel Sambuc // CHECK1: getelementptr inbounds [[T]]* {{.*}}, i32 0, i32 2 54*f4a2713aSLionel Sambuc // CHECK1-NEXT: load %struct.A** 55*f4a2713aSLionel Sambuc // CHECK1-NEXT: getelementptr inbounds %struct.A* 56*f4a2713aSLionel Sambuc // CHECK1-NEXT: store float 57*f4a2713aSLionel Sambuc // 58*f4a2713aSLionel Sambuc // CHECK1: getelementptr inbounds [[T]]* {{.*}}, i32 0, i32 2 59*f4a2713aSLionel Sambuc // CHECK1-NEXT: load %struct.A** 60*f4a2713aSLionel Sambuc // CHECK1-NEXT: getelementptr inbounds %struct.A* 61*f4a2713aSLionel Sambuc // CHECK1-NEXT: store i8 99 62*f4a2713aSLionel Sambuc } 63*f4a2713aSLionel Sambuc } 64*f4a2713aSLionel Sambuc } 65*f4a2713aSLionel Sambuc } 66*f4a2713aSLionel Sambuc 67*f4a2713aSLionel Sambuc void test_nest_block() { 68*f4a2713aSLionel Sambuc __block int x; 69*f4a2713aSLionel Sambuc int y; 70*f4a2713aSLionel Sambuc ^{ 71*f4a2713aSLionel Sambuc int z; 72*f4a2713aSLionel Sambuc x = z; 73*f4a2713aSLionel Sambuc #pragma clang __debug captured 74*f4a2713aSLionel Sambuc { 75*f4a2713aSLionel Sambuc z = y; // OK 76*f4a2713aSLionel Sambuc } 77*f4a2713aSLionel Sambuc }(); 78*f4a2713aSLionel Sambuc 79*f4a2713aSLionel Sambuc // CHECK2: define internal void @{{.*}}test_nest_block_block_invoke 80*f4a2713aSLionel Sambuc // 81*f4a2713aSLionel Sambuc // CHECK2: [[Z:%[0-9a-z_]*]] = alloca i32 82*f4a2713aSLionel Sambuc // CHECK2: alloca %struct.anon{{.*}} 83*f4a2713aSLionel Sambuc // 84*f4a2713aSLionel Sambuc // CHECK2: store i32 85*f4a2713aSLionel Sambuc // CHECK2: store i32* [[Z]] 86*f4a2713aSLionel Sambuc // 87*f4a2713aSLionel Sambuc // CHECK2: getelementptr inbounds %struct.anon 88*f4a2713aSLionel Sambuc // CHECK2-NEXT: getelementptr inbounds 89*f4a2713aSLionel Sambuc // CHECK2-NEXT: store i32* 90*f4a2713aSLionel Sambuc // 91*f4a2713aSLionel Sambuc // CHECK2: call void @__captured_stmt 92*f4a2713aSLionel Sambuc 93*f4a2713aSLionel Sambuc int a; 94*f4a2713aSLionel Sambuc #pragma clang __debug captured 95*f4a2713aSLionel Sambuc { 96*f4a2713aSLionel Sambuc __block int b; 97*f4a2713aSLionel Sambuc int c; 98*f4a2713aSLionel Sambuc __block int d; 99*f4a2713aSLionel Sambuc ^{ 100*f4a2713aSLionel Sambuc b = a; 101*f4a2713aSLionel Sambuc b = c; 102*f4a2713aSLionel Sambuc b = d; 103*f4a2713aSLionel Sambuc }(); 104*f4a2713aSLionel Sambuc } 105*f4a2713aSLionel Sambuc 106*f4a2713aSLionel Sambuc // CHECK2: alloca %struct.__block_byref_b 107*f4a2713aSLionel Sambuc // CHECK2-NEXT: [[C:%[0-9a-z_]*]] = alloca i32 108*f4a2713aSLionel Sambuc // CHECK2-NEXT: alloca %struct.__block_byref_d 109*f4a2713aSLionel Sambuc // 110*f4a2713aSLionel Sambuc // CHECK2: bitcast %struct.__block_byref_b* 111*f4a2713aSLionel Sambuc // CHECK2-NEXT: store i8* 112*f4a2713aSLionel Sambuc // 113*f4a2713aSLionel Sambuc // CHECK2: [[CapA:%[0-9a-z_.]*]] = getelementptr inbounds {{.*}}, i32 0, i32 7 114*f4a2713aSLionel Sambuc // 115*f4a2713aSLionel Sambuc // CHECK2: getelementptr inbounds %struct.anon{{.*}}, i32 0, i32 0 116*f4a2713aSLionel Sambuc // CHECK2: load i32** 117*f4a2713aSLionel Sambuc // CHECK2: load i32* 118*f4a2713aSLionel Sambuc // CHECK2: store i32 {{.*}}, i32* [[CapA]] 119*f4a2713aSLionel Sambuc // 120*f4a2713aSLionel Sambuc // CHECK2: [[CapC:%[0-9a-z_.]*]] = getelementptr inbounds {{.*}}, i32 0, i32 8 121*f4a2713aSLionel Sambuc // CHECK2-NEXT: [[Val:%[0-9a-z_]*]] = load i32* [[C]] 122*f4a2713aSLionel Sambuc // CHECK2-NEXT: store i32 [[Val]], i32* [[CapC]] 123*f4a2713aSLionel Sambuc // 124*f4a2713aSLionel Sambuc // CHECK2: bitcast %struct.__block_byref_d* 125*f4a2713aSLionel Sambuc // CHECK2-NEXT: store i8* 126*f4a2713aSLionel Sambuc } 127