diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -188,6 +188,7 @@ ENUM_CODEGENOPT(ObjCDispatchMethod, ObjCDispatchMethodKind, 2, Legacy) /// Replace certain message sends with calls to ObjC runtime entrypoints CODEGENOPT(ObjCConvertMessagesToRuntimeCalls , 1, 1) +CODEGENOPT(ObjCAvoidHeapifyLocalBlocks, 1, 0) VALUE_CODEGENOPT(OptimizationLevel, 2, 0) ///< The -O[0-3] option specified. VALUE_CODEGENOPT(OptimizeSize, 2, 0) ///< If -Os (==1) or -Oz (==2) is specified. diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -2373,6 +2373,11 @@ Group, Flags<[CC1Option]>, HelpText<"Ignore attribute objc_direct so that direct methods can be tested">, MarshallingInfoFlag>; +defm objc_avoid_heapify_local_blocks : BoolFOption<"objc-avoid-heapify-local-blocks", + CodeGenOpts<"ObjCAvoidHeapifyLocalBlocks">, DefaultFalse, + PosFlag, + NegFlag, + BothFlags<[], " to avoid heapifying local blocks">>; def fomit_frame_pointer : Flag<["-"], "fomit-frame-pointer">, Group; def fopenmp : Flag<["-"], "fopenmp">, Group, Flags<[CC1Option, NoArgumentUnused, FlangOption, FC1Option]>, diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp --- a/clang/lib/CodeGen/CGObjC.cpp +++ b/clang/lib/CodeGen/CGObjC.cpp @@ -3344,7 +3344,8 @@ TryEmitResult result = visitExpr(e); // Avoid the block-retain if this is a block literal that doesn't need to be // copied to the heap. - if (e->getBlockDecl()->canAvoidCopyToHeap()) + if (CGF.CGM.getCodeGenOpts().ObjCAvoidHeapifyLocalBlocks && + e->getBlockDecl()->canAvoidCopyToHeap()) result.setInt(true); return result; } diff --git a/clang/test/CodeGenObjC/arc-block-copy-escape.m b/clang/test/CodeGenObjC/arc-block-copy-escape.m --- a/clang/test/CodeGenObjC/arc-block-copy-escape.m +++ b/clang/test/CodeGenObjC/arc-block-copy-escape.m @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 -fobjc-arc -fblocks -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -fobjc-arc -fblocks -emit-llvm %s -o - | FileCheck -check-prefix=CHECK -check-prefix=CHECK-HEAP %s +// RUN: %clang_cc1 -fobjc-arc -fblocks -fobjc-avoid-heapify-local-blocks -emit-llvm %s -o - | FileCheck -check-prefix=CHECK -check-prefix=CHECK-NOHEAP %s + typedef void (^block_t)(void); void use_block(block_t); @@ -8,17 +10,19 @@ void test0(int i) { block_t block = ^{ use_int(i); }; - // CHECK-LABEL: define {{.*}}void @test0( - // CHECK-NOT: @llvm.objc.retainBlock( - // CHECK: ret void + // CHECK-LABEL: define {{.*}}void @test0( + // CHECK-HEAP: call {{.*}}i8* @llvm.objc.retainBlock(i8* {{%.*}}) [[NUW:#[0-9]+]], !clang.arc.copy_on_escape + // CHECK-NOHEAP-NOT: @llvm.objc.retainBlock( + // CHECK: ret void } void test1(int i) { id block = ^{ use_int(i); }; // CHECK-LABEL: define {{.*}}void @test1( - // CHECK: call {{.*}}i8* @llvm.objc.retainBlock(i8* {{%.*}}) [[NUW:#[0-9]+]] - // CHECK-NOT: !clang.arc.copy_on_escape - // CHECK: ret void + // CHECK-HEAP: call {{.*}}i8* @llvm.objc.retainBlock(i8* {{%.*}}) [[NUW]] + // CHECK-NOHEAP: call {{.*}}i8* @llvm.objc.retainBlock(i8* {{%.*}}) [[NUW:#[0-9]+]] + // CHECK-NOT: !clang.arc.copy_on_escape + // CHECK: ret void } // CHECK: attributes [[NUW]] = { nounwind } diff --git a/clang/test/CodeGenObjC/arc-blocks.m b/clang/test/CodeGenObjC/arc-blocks-avoid-heapify.m copy from clang/test/CodeGenObjC/arc-blocks.m copy to clang/test/CodeGenObjC/arc-blocks-avoid-heapify.m --- a/clang/test/CodeGenObjC/arc-blocks.m +++ b/clang/test/CodeGenObjC/arc-blocks-avoid-heapify.m @@ -1,11 +1,10 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -O2 -disable-llvm-passes -o - %s | FileCheck -check-prefix=CHECK -check-prefix=CHECK-COMMON %s -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck -check-prefix=CHECK-UNOPT -check-prefix=CHECK-COMMON %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -O2 -disable-llvm-passes -fobjc-avoid-heapify-local-blocks -o - %s | FileCheck %s -// CHECK-COMMON: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 } -// CHECK-COMMON: @[[BLOCK_DESCRIPTOR_TMP44:.*]] = linkonce_odr hidden unnamed_addr constant { i64, i64, i8*, i8*, i8*, i64 } { i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32s to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32s to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, align 8 -// CHECK-COMMON: @[[BLOCK_DESCRIPTOR_TMP9:.*]] = linkonce_odr hidden unnamed_addr constant { i64, i64, i8*, i8*, i8*, i64 } { i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32r to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32r to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 16 }, align 8 -// CHECK-COMMON: @[[BLOCK_DESCRIPTOR_TMP46:.*]] = linkonce_odr hidden unnamed_addr constant { i64, i64, i8*, i8*, i8*, i8* } { i64 0, i64 48, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32s to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32s to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @{{.*}}, i32 0, i32 0) }, align 8 -// CHECK-COMMON: @[[BLOCK_DESCRIPTOR_TMP48:.*]] = linkonce_odr hidden unnamed_addr constant { i64, i64, i8*, i8*, i8*, i64 } { i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32b to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32s to i8*), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, align 8 +// CHECK: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 } +// CHECK: @[[BLOCK_DESCRIPTOR_TMP44:.*]] = linkonce_odr hidden unnamed_addr constant { i64, i64, i8*, i8*, i8*, i64 } { i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32s to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32s to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, align 8 +// CHECK: @[[BLOCK_DESCRIPTOR_TMP9:.*]] = linkonce_odr hidden unnamed_addr constant { i64, i64, i8*, i8*, i8*, i64 } { i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32r to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32r to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 16 }, align 8 +// CHECK: @[[BLOCK_DESCRIPTOR_TMP46:.*]] = linkonce_odr hidden unnamed_addr constant { i64, i64, i8*, i8*, i8*, i8* } { i64 0, i64 48, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32s to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32s to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @{{.*}}, i32 0, i32 0) }, align 8 +// CHECK: @[[BLOCK_DESCRIPTOR_TMP48:.*]] = linkonce_odr hidden unnamed_addr constant { i64, i64, i8*, i8*, i8*, i64 } { i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32b to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32s to i8*), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, align 8 // This shouldn't crash. void test0(id (^maker)(void)) { @@ -617,22 +616,6 @@ // CHECK-NEXT: br label void test18(id x) { -// CHECK-UNOPT-LABEL: define{{.*}} void @test18( -// CHECK-UNOPT: [[X:%.*]] = alloca i8*, -// CHECK-UNOPT-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], -// CHECK-UNOPT-NEXT: store i8* null, i8** [[X]] -// CHECK-UNOPT-NEXT: call void @llvm.objc.storeStrong(i8** [[X]], -// CHECK-UNOPT: %[[BLOCK_DESCRIPTOR:.*]] = getelementptr inbounds [[BLOCK_T]], [[BLOCK_T]]* [[BLOCK]], i32 0, i32 4 -// CHECK-UNOPT: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i64, i64, i8*, i8*, i8*, i64 }* @[[BLOCK_DESCRIPTOR_TMP44]] to %[[STRUCT_BLOCK_DESCRIPTOR]]*), %[[STRUCT_BLOCK_DESCRIPTOR]]** %[[BLOCK_DESCRIPTOR]], align 8 -// CHECK-UNOPT: [[SLOT:%.*]] = getelementptr inbounds [[BLOCK_T]], [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 -// CHECK-UNOPT-NEXT: [[T0:%.*]] = load i8*, i8** [[X]], -// CHECK-UNOPT-NEXT: [[T1:%.*]] = call i8* @llvm.objc.retain(i8* [[T0]]) -// CHECK-UNOPT-NEXT: store i8* [[T1]], i8** [[SLOT]], -// CHECK-UNOPT-NEXT: bitcast -// CHECK-UNOPT-NEXT: call void @test18_helper( -// CHECK-UNOPT-NEXT: call void @llvm.objc.storeStrong(i8** [[SLOT]], i8* null) [[NUW:#[0-9]+]] -// CHECK-UNOPT-NEXT: call void @llvm.objc.storeStrong(i8** [[X]], i8* null) [[NUW]] -// CHECK-UNOPT-NEXT: ret void extern void test18_helper(id (^)(void)); test18_helper(^{ return x; }); } @@ -649,7 +632,6 @@ // CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i64, i64, i8*, i8*, i8*, i8* }* @[[BLOCK_DESCRIPTOR_TMP46]] to %[[STRUCT_BLOCK_DESCRIPTOR]]*), %[[STRUCT_BLOCK_DESCRIPTOR]]** %[[BLOCK_DESCRIPTOR]], align 8 // CHECK-LABEL: define internal void @__testUnsafeUnretainedLifetimeInCopyAndDestroyHelpers_block_invoke -// CHECK-UNOPT-LABEL: define internal void @__testUnsafeUnretainedLifetimeInCopyAndDestroyHelpers_block_invoke // rdar://13588325 void test19_sink(void (^)(int)); @@ -705,15 +687,6 @@ // CHECK-NEXT: call void @llvm.objc.release(i8* [[X]]) // CHECK-NEXT: ret void -// CHECK-UNOPT-LABEL: define{{.*}} void @test20( -// CHECK-UNOPT: [[XADDR:%.*]] = alloca i8* -// CHECK-UNOPT-NEXT: [[BLOCK:%.*]] = alloca <[[BLOCKTY:.*]]> -// CHECK-UNOPT: [[BLOCKCAPTURED:%.*]] = getelementptr inbounds <[[BLOCKTY]]>, <[[BLOCKTY]]>* [[BLOCK]], i32 0, i32 5 -// CHECK-UNOPT: [[CAPTURED:%.*]] = load i8*, i8** [[XADDR]] -// CHECK-UNOPT: [[RETAINED:%.*]] = call i8* @llvm.objc.retain(i8* [[CAPTURED]]) -// CHECK-UNOPT: store i8* [[RETAINED]], i8** [[BLOCKCAPTURED]] -// CHECK-UNOPT: call void @llvm.objc.storeStrong(i8** [[BLOCKCAPTURED]], i8* null) - void test20_callee(void (^)()); void test20(const id x) { test20_callee(^{ (void)x; }); @@ -732,12 +705,11 @@ // The lifetime of 'x', which is captured by the block in the statement // expression, should be extended. -// CHECK-COMMON-LABEL: define{{.*}} i8* @test22( -// CHECK-COMMON: %[[BLOCK_CAPTURED:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %{{.*}}*, i8* }>, <{ i8*, i32, i32, i8*, %{{.*}}*, i8* }>* %{{.*}}, i32 0, i32 5 -// CHECK-COMMON: %[[V3:.*]] = call i8* @llvm.objc.retain(i8* %{{.*}}) -// CHECK-COMMON: store i8* %[[V3]], i8** %[[BLOCK_CAPTURED]], align 8 -// CHECK-COMMON: call void @test22_1() -// CHECK-UNOPT: call void @llvm.objc.storeStrong(i8** %[[BLOCK_CAPTURED]], i8* null) +// CHECK-LABEL: define{{.*}} i8* @test22( +// CHECK: %[[BLOCK_CAPTURED:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %{{.*}}*, i8* }>, <{ i8*, i32, i32, i8*, %{{.*}}*, i8* }>* %{{.*}}, i32 0, i32 5 +// CHECK: %[[V3:.*]] = call i8* @llvm.objc.retain(i8* %{{.*}}) +// CHECK: store i8* %[[V3]], i8** %[[BLOCK_CAPTURED]], align 8 +// CHECK: call void @test22_1() // CHECK: %[[V15:.*]] = load i8*, i8** %[[BLOCK_CAPTURED]], align 8 // CHECK: call void @llvm.objc.release(i8* %[[V15]]) @@ -751,14 +723,13 @@ -(void)m:(int)i, ...; @end -// CHECK-COMMON-LABEL: define{{.*}} void @test23( -// CHECK-COMMON: %[[V9:.*]] = call i8* @llvm.objc.retainBlock( -// CHECK-COMMON: %[[V10:.*]] = bitcast i8* %[[V9]] to void ()* -// CHECK-COMMON: call void (i8*, i8*, i32, ...) bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i32, ...)*)(i8* %{{.*}}, i8* %{{.*}}, i32 123, void ()* %[[V10]]) +// CHECK-LABEL: define{{.*}} void @test23( +// CHECK: %[[V9:.*]] = call i8* @llvm.objc.retainBlock( +// CHECK: %[[V10:.*]] = bitcast i8* %[[V9]] to void ()* +// CHECK: call void (i8*, i8*, i32, ...) bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i32, ...)*)(i8* %{{.*}}, i8* %{{.*}}, i32 123, void ()* %[[V10]]) void test23(id x, Test23 *t) { [t m:123, ^{ (void)x; }]; } // CHECK: attributes [[NUW]] = { nounwind } -// CHECK-UNOPT: attributes [[NUW]] = { nounwind } diff --git a/clang/test/CodeGenObjC/arc-blocks.m b/clang/test/CodeGenObjC/arc-blocks.m --- a/clang/test/CodeGenObjC/arc-blocks.m +++ b/clang/test/CodeGenObjC/arc-blocks.m @@ -336,19 +336,20 @@ __block void (^block)(void) = ^{ block(); }; // CHECK-LABEL: define{{.*}} void @test10a() // CHECK: [[BYREF:%.*]] = alloca [[BYREF_T:%.*]], - // CHECK: [[BLOCK1:%.*]] = alloca <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>, align 8 // Zero-initialization before running the initializer. // CHECK: [[T0:%.*]] = getelementptr inbounds [[BYREF_T]], [[BYREF_T]]* [[BYREF]], i32 0, i32 6 // CHECK-NEXT: store void ()* null, void ()** [[T0]], align 8 // Run the initializer as an assignment. - // CHECK: [[T2:%.*]] = bitcast <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>* [[BLOCK1]] to void ()* + // CHECK: [[T0:%.*]] = bitcast void ()* {{%.*}} to i8* + // CHECK-NEXT: [[T1:%.*]] = call i8* @llvm.objc.retainBlock(i8* [[T0]]) + // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to void ()* // CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds [[BYREF_T]], [[BYREF_T]]* [[BYREF]], i32 0, i32 1 // CHECK-NEXT: [[T4:%.*]] = load [[BYREF_T]]*, [[BYREF_T]]** [[T3]] // CHECK-NEXT: [[T5:%.*]] = getelementptr inbounds [[BYREF_T]], [[BYREF_T]]* [[T4]], i32 0, i32 6 // CHECK-NEXT: [[T6:%.*]] = load void ()*, void ()** [[T5]], align 8 - // CHECK-NEXT: store void ()* [[T2]], void ()** [[T5]], align 8 + // CHECK-NEXT: store void ()* {{%.*}}, void ()** [[T5]], align 8 // CHECK-NEXT: [[T7:%.*]] = bitcast void ()* [[T6]] to i8* // CHECK-NEXT: call void @llvm.objc.release(i8* [[T7]]) @@ -407,12 +408,14 @@ // CHECK-NEXT: [[SLOT:%.*]] = getelementptr inbounds [[BYREF_T]], [[BYREF_T]]* [[BYREF]], i32 0, i32 6 // The assignment. - // CHECK: [[T2:%.*]] = bitcast <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>* [[BLOCK3]] to void ()* + // CHECK: [[T0:%.*]] = bitcast void ()* {{%.*}} to i8* + // CHECK-NEXT: [[T1:%.*]] = call i8* @llvm.objc.retainBlock(i8* [[T0]]) + // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to void ()* // CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds [[BYREF_T]], [[BYREF_T]]* [[BYREF]], i32 0, i32 1 // CHECK-NEXT: [[T4:%.*]] = load [[BYREF_T]]*, [[BYREF_T]]** [[T3]] // CHECK-NEXT: [[T5:%.*]] = getelementptr inbounds [[BYREF_T]], [[BYREF_T]]* [[T4]], i32 0, i32 6 // CHECK-NEXT: [[T6:%.*]] = load void ()*, void ()** [[T5]], align 8 - // CHECK-NEXT: store void ()* [[T2]], void ()** [[T5]], align 8 + // CHECK-NEXT: store void ()* {{%.*}}, void ()** [[T5]], align 8 // CHECK-NEXT: [[T7:%.*]] = bitcast void ()* [[T6]] to i8* // CHECK-NEXT: call void @llvm.objc.release(i8* [[T7]]) diff --git a/clang/test/CodeGenObjCXX/arc-blocks.mm b/clang/test/CodeGenObjCXX/arc-blocks.mm --- a/clang/test/CodeGenObjCXX/arc-blocks.mm +++ b/clang/test/CodeGenObjCXX/arc-blocks.mm @@ -1,9 +1,11 @@ // RUN: %clang_cc1 -std=gnu++98 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-runtime-has-weak -fblocks -fobjc-arc -fexceptions -fobjc-arc-exceptions -o - %s | FileCheck -check-prefix CHECK %s // RUN: %clang_cc1 -std=gnu++98 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-runtime-has-weak -fblocks -fobjc-arc -fexceptions -fobjc-arc-exceptions -O1 -o - %s | FileCheck -check-prefix CHECK-O1 %s // RUN: %clang_cc1 -std=gnu++98 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-runtime-has-weak -fblocks -fobjc-arc -o - %s | FileCheck -check-prefix CHECK-NOEXCP %s +// RUN: %clang_cc1 -std=gnu++98 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-runtime-has-weak -fblocks -fobjc-arc -fexceptions -fobjc-arc-exceptions -fobjc-avoid-heapify-local-blocks -o - %s | FileCheck -check-prefix CHECK-NOHEAP %s // CHECK: [[A:.*]] = type { i64, [10 x i8*] } // CHECK: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 } +// CHECK-NOHEAP: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 } // CHECK: %[[STRUCT_TEST1_S0:.*]] = type { i32 } // CHECK: %[[STRUCT_TRIVIAL_INTERNAL:.*]] = type { i32 } @@ -209,8 +211,8 @@ namespace test_block_retain { -// CHECK-LABEL: define{{.*}} void @_ZN17test_block_retain14initializationEP11objc_object( -// CHECK-NOT: @llvm.objc.retainBlock( +// CHECK-NOHEAP-LABEL: define{{.*}} void @_ZN17test_block_retain14initializationEP11objc_object( +// CHECK-NOHEAP-NOT: @llvm.objc.retainBlock( void initialization(id a) { BlockTy b0 = ^{ foo1(a); }; BlockTy b1 = (^{ foo1(a); }); @@ -218,23 +220,23 @@ b1(); } -// CHECK-LABEL: define{{.*}} void @_ZN17test_block_retain20initializationStaticEP11objc_object( -// CHECK: @llvm.objc.retainBlock( +// CHECK-NOHEAP-LABEL: define{{.*}} void @_ZN17test_block_retain20initializationStaticEP11objc_object( +// CHECK-NOHEAP: @llvm.objc.retainBlock( void initializationStatic(id a) { static BlockTy b0 = ^{ foo1(a); }; b0(); } -// CHECK-LABEL: define{{.*}} void @_ZN17test_block_retain15initialization2EP11objc_object -// CHECK: %[[B0:.*]] = alloca void ()*, align 8 -// CHECK: %[[B1:.*]] = alloca void ()*, align 8 -// CHECK: load void ()*, void ()** %[[B0]], align 8 -// CHECK-NOT: @llvm.objc.retainBlock -// CHECK: %[[V9:.*]] = load void ()*, void ()** %[[B0]], align 8 -// CHECK: %[[V10:.*]] = bitcast void ()* %[[V9]] to i8* -// CHECK: %[[V11:.*]] = call i8* @llvm.objc.retainBlock(i8* %[[V10]]) -// CHECK: %[[V12:.*]] = bitcast i8* %[[V11]] to void ()* -// CHECK: store void ()* %[[V12]], void ()** %[[B1]], align 8 +// CHECK-NOHEAP-LABEL: define{{.*}} void @_ZN17test_block_retain15initialization2EP11objc_object +// CHECK-NOHEAP: %[[B0:.*]] = alloca void ()*, align 8 +// CHECK-NOHEAP: %[[B1:.*]] = alloca void ()*, align 8 +// CHECK-NOHEAP: load void ()*, void ()** %[[B0]], align 8 +// CHECK-NOHEAP-NOT: @llvm.objc.retainBlock +// CHECK-NOHEAP: %[[V9:.*]] = load void ()*, void ()** %[[B0]], align 8 +// CHECK-NOHEAP: %[[V10:.*]] = bitcast void ()* %[[V9]] to i8* +// CHECK-NOHEAP: %[[V11:.*]] = call i8* @llvm.objc.retainBlock(i8* %[[V10]]) +// CHECK-NOHEAP: %[[V12:.*]] = bitcast i8* %[[V11]] to void ()* +// CHECK-NOHEAP: store void ()* %[[V12]], void ()** %[[B1]], align 8 void initialization2(id a) { BlockTy b0 = ^{ foo1(a); }; b0(); @@ -242,8 +244,8 @@ b1(); } -// CHECK-LABEL: define{{.*}} void @_ZN17test_block_retain10assignmentEP11objc_object( -// CHECK-NOT: @llvm.objc.retainBlock( +// CHECK-NOHEAP-LABEL: define{{.*}} void @_ZN17test_block_retain10assignmentEP11objc_object( +// CHECK-NOHEAP-NOT: @llvm.objc.retainBlock( void assignment(id a) { BlockTy b0; (b0) = ^{ foo1(a); }; @@ -252,16 +254,16 @@ b0(); } -// CHECK-LABEL: define{{.*}} void @_ZN17test_block_retain16assignmentStaticEP11objc_object( -// CHECK: @llvm.objc.retainBlock( +// CHECK-NOHEAP-LABEL: define{{.*}} void @_ZN17test_block_retain16assignmentStaticEP11objc_object( +// CHECK-NOHEAP: @llvm.objc.retainBlock( void assignmentStatic(id a) { static BlockTy b0; b0 = ^{ foo1(a); }; b0(); } -// CHECK-LABEL: define{{.*}} void @_ZN17test_block_retain21assignmentConditionalEP11objc_objectb( -// CHECK: @llvm.objc.retainBlock( +// CHECK-NOHEAP-LABEL: define{{.*}} void @_ZN17test_block_retain21assignmentConditionalEP11objc_objectb( +// CHECK-NOHEAP: @llvm.objc.retainBlock( void assignmentConditional(id a, bool c) { BlockTy b0; if (c) @@ -270,16 +272,16 @@ b0(); } -// CHECK-LABEL: define{{.*}} void @_ZN17test_block_retain11assignment2EP11objc_object( -// CHECK: %[[B0:.*]] = alloca void ()*, align 8 -// CHECK: %[[B1:.*]] = alloca void ()*, align 8 -// CHECK-NOT: @llvm.objc.retainBlock -// CHECK: store void ()* null, void ()** %[[B1]], align 8 -// CHECK: %[[V9:.*]] = load void ()*, void ()** %[[B0]], align 8 -// CHECK: %[[V10:.*]] = bitcast void ()* %[[V9]] to i8* -// CHECK: %[[V11:.*]] = call i8* @llvm.objc.retainBlock(i8* %[[V10]] -// CHECK: %[[V12:.*]] = bitcast i8* %[[V11]] to void ()* -// CHECK: store void ()* %[[V12]], void ()** %[[B1]], align 8 +// CHECK-NOHEAP-LABEL: define{{.*}} void @_ZN17test_block_retain11assignment2EP11objc_object( +// CHECK-NOHEAP: %[[B0:.*]] = alloca void ()*, align 8 +// CHECK-NOHEAP: %[[B1:.*]] = alloca void ()*, align 8 +// CHECK-NOHEAP-NOT: @llvm.objc.retainBlock +// CHECK-NOHEAP: store void ()* null, void ()** %[[B1]], align 8 +// CHECK-NOHEAP: %[[V9:.*]] = load void ()*, void ()** %[[B0]], align 8 +// CHECK-NOHEAP: %[[V10:.*]] = bitcast void ()* %[[V9]] to i8* +// CHECK-NOHEAP: %[[V11:.*]] = call i8* @llvm.objc.retainBlock(i8* %[[V10]] +// CHECK-NOHEAP: %[[V12:.*]] = bitcast i8* %[[V11]] to void ()* +// CHECK-NOHEAP: store void ()* %[[V12]], void ()** %[[B1]], align 8 void assignment2(id a) { BlockTy b0 = ^{ foo1(a); }; b0(); @@ -290,30 +292,30 @@ // We cannot remove the call to @llvm.objc.retainBlock if the variable is of type id. -// CHECK: define{{.*}} void @_ZN17test_block_retain21initializationObjCPtrEP11objc_object( -// CHECK: alloca i8*, align 8 -// CHECK: %[[B0:.*]] = alloca i8*, align 8 -// CHECK: %[[BLOCK:.*]] = alloca <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>, align 8 -// CHECK: %[[V3:.*]] = bitcast <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>* %[[BLOCK]] to void ()* -// CHECK: %[[V4:.*]] = bitcast void ()* %[[V3]] to i8* -// CHECK: %[[V5:.*]] = call i8* @llvm.objc.retainBlock(i8* %[[V4]]) -// CHECK: %[[V6:.*]] = bitcast i8* %[[V5]] to void ()* -// CHECK: %[[V7:.*]] = bitcast void ()* %[[V6]] to i8* -// CHECK: store i8* %[[V7]], i8** %[[B0]], align 8 +// CHECK-NOHEAP: define{{.*}} void @_ZN17test_block_retain21initializationObjCPtrEP11objc_object( +// CHECK-NOHEAP: alloca i8*, align 8 +// CHECK-NOHEAP: %[[B0:.*]] = alloca i8*, align 8 +// CHECK-NOHEAP: %[[BLOCK:.*]] = alloca <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>, align 8 +// CHECK-NOHEAP: %[[V3:.*]] = bitcast <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>* %[[BLOCK]] to void ()* +// CHECK-NOHEAP: %[[V4:.*]] = bitcast void ()* %[[V3]] to i8* +// CHECK-NOHEAP: %[[V5:.*]] = call i8* @llvm.objc.retainBlock(i8* %[[V4]]) +// CHECK-NOHEAP: %[[V6:.*]] = bitcast i8* %[[V5]] to void ()* +// CHECK-NOHEAP: %[[V7:.*]] = bitcast void ()* %[[V6]] to i8* +// CHECK-NOHEAP: store i8* %[[V7]], i8** %[[B0]], align 8 void initializationObjCPtr(id a) { id b0 = ^{ foo1(a); }; ((BlockTy)b0)(); } -// CHECK: define{{.*}} void @_ZN17test_block_retain17assignmentObjCPtrEP11objc_object( -// CHECK: %[[B0:.*]] = alloca void ()*, align 8 -// CHECK: %[[B1:.*]] = alloca i8*, align 8 -// CHECK: %[[V4:.*]] = load void ()*, void ()** %[[B0]], align 8 -// CHECK: %[[V5:.*]] = bitcast void ()* %[[V4]] to i8* -// CHECK: %[[V6:.*]] = call i8* @llvm.objc.retainBlock(i8* %[[V5]]) -// CHECK: %[[V7:.*]] = bitcast i8* %[[V6]] to void ()* -// CHECK: %[[V8:.*]] = bitcast void ()* %[[V7]] to i8* -// CHECK: store i8* %[[V8]], i8** %[[B1]], align 8 +// CHECK-NOHEAP: define{{.*}} void @_ZN17test_block_retain17assignmentObjCPtrEP11objc_object( +// CHECK-NOHEAP: %[[B0:.*]] = alloca void ()*, align 8 +// CHECK-NOHEAP: %[[B1:.*]] = alloca i8*, align 8 +// CHECK-NOHEAP: %[[V4:.*]] = load void ()*, void ()** %[[B0]], align 8 +// CHECK-NOHEAP: %[[V5:.*]] = bitcast void ()* %[[V4]] to i8* +// CHECK-NOHEAP: %[[V6:.*]] = call i8* @llvm.objc.retainBlock(i8* %[[V5]]) +// CHECK-NOHEAP: %[[V7:.*]] = bitcast i8* %[[V6]] to void ()* +// CHECK-NOHEAP: %[[V8:.*]] = bitcast void ()* %[[V7]] to i8* +// CHECK-NOHEAP: store i8* %[[V8]], i8** %[[B1]], align 8 void assignmentObjCPtr(id a) { BlockTy b0 = ^{ foo1(a); }; id b1; diff --git a/clang/test/PCH/arc-blocks.mm b/clang/test/PCH/arc-blocks.mm --- a/clang/test/PCH/arc-blocks.mm +++ b/clang/test/PCH/arc-blocks.mm @@ -1,5 +1,5 @@ // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc -fblocks -std=c++1y -emit-pch %s -o %t -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc -fblocks -std=c++1y -include-pch %t -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc -fblocks -std=c++1y -include-pch %t -fobjc-avoid-heapify-local-blocks -emit-llvm -o - %s | FileCheck %s #ifndef HEADER_INCLUDED #define HEADER_INCLUDED