[clang] 37fa9d6 - [CodeGen][ObjC] Don't extend lifetime of ObjC pointers passed to calls

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 10 22:25:00 PDT 2020


Author: Akira Hatanaka
Date: 2020-03-10T22:10:32-07:00
New Revision: 37fa9d65eaa7d8fae7e5b787c4e8ef0a982cead5

URL: https://github.com/llvm/llvm-project/commit/37fa9d65eaa7d8fae7e5b787c4e8ef0a982cead5
DIFF: https://github.com/llvm/llvm-project/commit/37fa9d65eaa7d8fae7e5b787c4e8ef0a982cead5.diff

LOG: [CodeGen][ObjC] Don't extend lifetime of ObjC pointers passed to calls
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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 090efaadc4c6..e2cd0f8814cc 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -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)) {

diff  --git a/clang/test/CodeGenObjC/os_log.m b/clang/test/CodeGenObjC/os_log.m
index 1dd39eebf383..4e70ef3e7574 100644
--- a/clang/test/CodeGenObjC/os_log.m
+++ b/clang/test/CodeGenObjC/os_log.m
@@ -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 @@
 // 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);


        


More information about the cfe-commits mailing list