From 3b60e174bc742d9ec313dd008b2b90a74406a314 Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Wed, 10 Apr 2019 06:20:23 +0000 Subject: [PATCH] [CodeGen][ObjC] Emit the retainRV marker as a module flag instead of named metadata. This fixes a bug where ARC contract wasn't inserting the retainRV marker when LTO was enabled, which caused objects returned from a function to be auto-released. rdar://problem/49464214 Differential Revision: https://reviews.llvm.org/D60302 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@358048 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGObjC.cpp | 12 ++++-------- test/CodeGenObjC/arc-unsafeclaim.m | 3 ++- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp index 69ced58795..d5906cf994 100644 --- a/lib/CodeGen/CGObjC.cpp +++ b/lib/CodeGen/CGObjC.cpp @@ -2161,14 +2161,10 @@ static void emitAutoreleasedReturnValueMarker(CodeGenFunction &CGF) { // with this marker yet, so leave a breadcrumb for the ARC // optimizer to pick up. } else { - llvm::NamedMDNode *metadata = - CGF.CGM.getModule().getOrInsertNamedMetadata( - "clang.arc.retainAutoreleasedReturnValueMarker"); - assert(metadata->getNumOperands() <= 1); - if (metadata->getNumOperands() == 0) { - auto &ctx = CGF.getLLVMContext(); - metadata->addOperand(llvm::MDNode::get(ctx, - llvm::MDString::get(ctx, assembly))); + const char *markerKey = "clang.arc.retainAutoreleasedReturnValueMarker"; + if (!CGF.CGM.getModule().getModuleFlag(markerKey)) { + auto *str = llvm::MDString::get(CGF.getLLVMContext(), assembly); + CGF.CGM.getModule().addModuleFlag(llvm::Module::Error, markerKey, str); } } } diff --git a/test/CodeGenObjC/arc-unsafeclaim.m b/test/CodeGenObjC/arc-unsafeclaim.m index f5982ddc04..a8011e0241 100644 --- a/test/CodeGenObjC/arc-unsafeclaim.m +++ b/test/CodeGenObjC/arc-unsafeclaim.m @@ -231,4 +231,5 @@ void test_cast_to_void() { // This is always at the end of the module. -// CHECK-OPTIMIZED: !clang.arc.retainAutoreleasedReturnValueMarker = !{!0} +// CHECK-OPTIMIZED: !llvm.module.flags = !{!0, +// CHECK-OPTIMIZED: !0 = !{i32 1, !"clang.arc.retainAutoreleasedReturnValueMarker", !"mov{{.*}}marker for objc_retainAutoreleaseReturnValue"} -- 2.40.0