[CodeGen][ObjC] Don't extend lifetime of ObjC pointers passed to calls
authorAkira Hatanaka <ahatanaka@apple.com>
Wed, 11 Mar 2020 05:01:45 +0000 (22:01 -0700)
committerAkira Hatanaka <ahatanaka@apple.com>
Wed, 11 Mar 2020 05:10:32 +0000 (22:10 -0700)
to __builtin_os_log_format if ARC isn't enabled

Fixes a bug introduced in this commit:
https://github.com/llvm/llvm-project/commit/f4d791f8332c2bb7e89849d0fe4ef48cb0a23229

rdar://problem/60301219

clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGenObjC/os_log.m

index 090efaa..e2cd0f8 100644 (file)
@@ -1325,7 +1325,8 @@ RValue CodeGenFunction::emitBuiltinOSLogFormat(const CallExpr &E) {
       // enclosing block scope.
       // FIXME: We only have to do this if the argument is a temporary, which
       //        gets released after the full expression.
-      if (TheExpr->getType()->isObjCRetainableType()) {
+      if (TheExpr->getType()->isObjCRetainableType() &&
+          getLangOpts().ObjCAutoRefCount) {
         assert(getEvaluationKind(TheExpr->getType()) == TEK_Scalar &&
                "Only scalar can be a ObjC retainable type");
         if (!isa<Constant>(ArgVal)) {
index 1dd39ee..4e70ef3 100644 (file)
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc -O2 -fno-experimental-new-pass-manager | FileCheck %s --check-prefixes=CHECK,CHECK-LEGACY
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc -O2 -fexperimental-new-pass-manager | FileCheck %s --check-prefixes=CHECK,CHECK-NEWPM
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc -O0 | FileCheck %s -check-prefix=CHECK-O0
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -O2 -disable-llvm-passes | FileCheck %s -check-prefix=CHECK-MRR
 
 // Make sure we emit clang.arc.use before calling objc_release as part of the
 // cleanup. This way we make sure the object will not be released until the
@@ -137,6 +138,9 @@ void os_log_pack_send(void *);
 // CHECK-O0: call void @llvm.objc.storeStrong(i8** %[[V13]], i8* null)
 // CHECK-O0: call void @llvm.objc.storeStrong(i8** %[[A_ADDR]], i8* null)
 
+// CHECK-MRR: define void @test_builtin_os_log2(
+// CHECK-MRR-NOT: call {{.*}} @llvm.objc
+
 void test_builtin_os_log2(void *buf, id a) {
   __builtin_os_log_format(buf, "capabilities: %@ %@", GenString(), a);
   os_log_pack_send(buf);