[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

llvm-svn: 358048
This commit is contained in:
Akira Hatanaka 2019-04-10 06:20:23 +00:00
parent 9ca9d32b6b
commit 60c3a3b6d0
2 changed files with 6 additions and 9 deletions

View File

@ -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);
}
}
}

View File

@ -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"}