From: Saleem Abdulrasool Date: Fri, 5 May 2017 18:39:06 +0000 (+0000) Subject: CodeGen: avoid use of @clang.arc.use intrinsic at O0 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=703c645447c4685c14022f7ce53869d11d514636;p=clang CodeGen: avoid use of @clang.arc.use intrinsic at O0 The clang.arc.use intrinsic is removed via the ARC Contract Pass. This pass is only executed in optimized builds (>= opt level 1). Prevent the optimization implemented in SVN r301667 from triggering at optimization level 0 like every other ARC use intrinsic usage. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@302270 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp index 791a57e61f..2b2a92dd60 100644 --- a/lib/CodeGen/CGBlocks.cpp +++ b/lib/CodeGen/CGBlocks.cpp @@ -623,9 +623,13 @@ static void enterBlockScope(CodeGenFunction &CGF, BlockDecl *block) { // For const-qualified captures, emit clang.arc.use to ensure the captured // object doesn't get released while we are still depending on its validity // within the block. - if (VT.isConstQualified() && VT.getObjCLifetime() == Qualifiers::OCL_Strong) + if (VT.isConstQualified() && + VT.getObjCLifetime() == Qualifiers::OCL_Strong && + CGF.CGM.getCodeGenOpts().OptimizationLevel != 0) { + assert(CGF.CGM.getLangOpts().ObjCAutoRefCount && + "expected ObjC ARC to be enabled"); destroyer = CodeGenFunction::emitARCIntrinsicUse; - else if (dtorKind == QualType::DK_objc_strong_lifetime) { + } else if (dtorKind == QualType::DK_objc_strong_lifetime) { destroyer = CodeGenFunction::destroyARCStrongImprecise; } else { destroyer = CGF.getDestroyer(dtorKind); diff --git a/test/CodeGenObjC/arc-foreach.m b/test/CodeGenObjC/arc-foreach.m index e34445704e..e3b3f1aa5c 100644 --- a/test/CodeGenObjC/arc-foreach.m +++ b/test/CodeGenObjC/arc-foreach.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -fblocks -fobjc-arc -fobjc-runtime-has-weak -triple x86_64-apple-darwin -emit-llvm %s -o %t-64.s -// RUN: FileCheck -check-prefix CHECK-LP64 --input-file=%t-64.s %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin -fblocks -fobjc-arc -fobjc-runtime-has-weak -emit-llvm %s -o - | FileCheck -check-prefix CHECK-LP64 %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -fblocks -fobjc-arc -fobjc-runtime-has-weak -emit-llvm %s -o - | FileCheck -check-prefix CHECK-LP64-OPT %s // rdar://9503326 // rdar://9606600 @@ -29,6 +29,11 @@ void test0(NSArray *array) { // CHECK-LP64-NEXT: [[BUFFER:%.*]] = alloca [16 x i8*], align 8 // CHECK-LP64-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], +// CHECK-LP64-OPT-LABEL: define void @test0 +// CHECK-LP64-OPT: [[STATE:%.*]] = alloca [[STATE_T:%.*]], align 8 +// CHECK-LP64-OPT-NEXT: [[BUFFER:%.*]] = alloca [16 x i8*], align 8 +// CHECK-LP64-OPT-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], align 8 + // Initialize 'array'. // CHECK-LP64-NEXT: store [[ARRAY_T]]* null, [[ARRAY_T]]** [[ARRAY]] // CHECK-LP64-NEXT: [[ZERO:%.*]] = bitcast [[ARRAY_T]]** [[ARRAY]] to i8** @@ -66,8 +71,12 @@ void test0(NSArray *array) { // CHECK-LP64-NEXT: store i8* [[T1]], i8** [[T0]] // CHECK-LP64-NEXT: [[BLOCK1:%.*]] = bitcast [[BLOCK_T]]* [[BLOCK]] // CHECK-LP64-NEXT: call void @use_block(void ()* [[BLOCK1]]) -// CHECK-LP64-NEXT: [[CAPTURE:%.*]] = load i8*, i8** [[D0]] -// CHECK-LP64: call void (...) @clang.arc.use(i8* [[CAPTURE]]) +// CHECK-LP64-NEXT: call void @objc_storeStrong(i8** [[D0]], i8* null) +// CHECK-LP64-NOT: call void (...) @clang.arc.use(i8* [[CAPTURE]]) + +// CHECK-LP64-OPT: [[D0:%.*]] = getelementptr inbounds [[BLOCK_T]], [[BLOCK_T]]* [[BLOCK]], i64 0, i32 5 +// CHECK-LP64-OPT: [[CAPTURE:%.*]] = load i8*, i8** [[D0]] +// CHECK-LP64-OPT: call void (...) @clang.arc.use(i8* [[CAPTURE]]) // CHECK-LP64: [[T0:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES_ // CHECK-LP64-NEXT: [[T1:%.*]] = bitcast [[ARRAY_T]]* [[SAVED_ARRAY]] to i8* @@ -200,15 +209,24 @@ NSArray *array4; // CHECK-LP64: [[T0:%.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, [[TY]]* }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, [[TY]]* }>* [[BLOCK]], i32 0, i32 5 // CHECK-LP64: [[BC:%.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, [[TY]]* }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, [[TY]]* }>* [[BLOCK]], i32 0, i32 5 // CHECK-LP64: [[T1:%.*]] = load [[TY]]*, [[TY]]** [[SELF_ADDR]] -// CHECK-LP64: store [[TY]]* [[T1]], [[TY]]** [[BC]] +// CHECK-LP64: store [[TY]]* [[T1]], [[TY]]** [[BC]], align 8 -// CHECK-LP64: [[T5:%.*]] = load [[TY]]*, [[TY]]** [[T0]] -// CHECK-LP64: call void (...) @clang.arc.use([[TY]]* [[T5]]) +// CHECK-LP64-OPT-LABEL: define internal void @"\01-[I1 foo2]"( +// CHECK-LP64-OPT: [[TY:%.*]]* %self +// CHECK-LP64-OPT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], +// CHECK-LP64-OPT: [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]], [[BLOCK_T]]* [[BLOCK]], i64 0, i32 5 + +// CHECK-LP64: [[T5:%.*]] = bitcast [[TY]]** [[T0]] to i8** +// CHECK-LP64: call void @objc_storeStrong(i8** [[T5]], i8* null) +// CHECK-LP64-NOT: call void (...) @clang.arc.use([[TY]]* [[T5]]) // CHECK-LP64: switch i32 {{%.*}}, label %[[UNREACHABLE:.*]] [ // CHECK-LP64-NEXT: i32 0, label %[[CLEANUP_CONT:.*]] // CHECK-LP64-NEXT: i32 2, label %[[FORCOLL_END:.*]] // CHECK-LP64-NEXT: ] +// CHECK-LP64-OPT: [[T5:%.*]] = load [[TY]]*, [[TY]]** [[T0]] +// CHECK-LP64-OPT: call void (...) @clang.arc.use([[TY]]* [[T5]]) + // CHECK-LP64: {{^|:}}[[CLEANUP_CONT]] // CHECK-LP64-NEXT: br label %[[FORCOLL_END]]