]> granicus.if.org Git - clang/commitdiff
CodeGen: avoid use of @clang.arc.use intrinsic at O0
authorSaleem Abdulrasool <compnerd@compnerd.org>
Fri, 5 May 2017 18:39:06 +0000 (18:39 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Fri, 5 May 2017 18:39:06 +0000 (18:39 +0000)
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

lib/CodeGen/CGBlocks.cpp
test/CodeGenObjC/arc-foreach.m

index 791a57e61f530c91ae28b0ed29a8e6dc26a52392..2b2a92dd60190cc8aacec9c5be8e60f11bfa89d2 100644 (file)
@@ -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);
index e34445704e3745eb660e9c224e8098e30f707bda..e3b3f1aa5ce46c76b61c6ad105e128e47c112e35 100644 (file)
@@ -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]]