Author: ahatanak
Date: Tue Apr  9 23:20:23 2019
New Revision: 358048

URL: http://llvm.org/viewvc/llvm-project?rev=358048&view=rev
Log:
[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

Modified:
    cfe/trunk/lib/CodeGen/CGObjC.cpp
    cfe/trunk/test/CodeGenObjC/arc-unsafeclaim.m

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=358048&r1=358047&r2=358048&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Tue Apr  9 23:20:23 2019
@@ -2161,14 +2161,10 @@ static void emitAutoreleasedReturnValueM
     // 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);
       }
     }
   }

Modified: cfe/trunk/test/CodeGenObjC/arc-unsafeclaim.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-unsafeclaim.m?rev=358048&r1=358047&r2=358048&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/arc-unsafeclaim.m (original)
+++ cfe/trunk/test/CodeGenObjC/arc-unsafeclaim.m Tue Apr  9 23:20:23 2019
@@ -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"}


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to