[llvm] cb62f67 - Revert "[Intrinsics][ObjC] Mark objc_retain and friends as thisreturn."
Jon Roelofs via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 20 09:22:22 PDT 2023
Author: Jon Roelofs
Date: 2023-10-20T09:22:12-07:00
New Revision: cb62f67088aaf79493350547f74870318b71acc5
URL: https://github.com/llvm/llvm-project/commit/cb62f67088aaf79493350547f74870318b71acc5
DIFF: https://github.com/llvm/llvm-project/commit/cb62f67088aaf79493350547f74870318b71acc5.diff
LOG: Revert "[Intrinsics][ObjC] Mark objc_retain and friends as thisreturn."
This reverts commit ed83797f3cbfc8fb2a1af63542f97d7ec1d5505a.
Reverting pending the investigation of https://github.com/llvm/llvm-project/issues/69658
Added:
Modified:
clang/lib/CodeGen/CGCall.cpp
clang/test/CodeGenObjC/arc.m
clang/test/CodeGenObjC/convert-messages-to-runtime-calls.m
llvm/include/llvm/IR/Intrinsics.td
llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
llvm/test/Transforms/PreISelIntrinsicLowering/X86/objc-arc.ll
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 150450e9165900f..e1e1ad7e6a17b20 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -3447,9 +3447,9 @@ static llvm::Value *tryRemoveRetainOfSelf(CodeGenFunction &CGF,
const VarDecl *self = method->getSelfDecl();
if (!self->getType().isConstQualified()) return nullptr;
- // Look for a retain call. Note: stripPointerCasts looks through returned arg
- // functions, which would cause us to miss the retain.
- llvm::CallInst *retainCall = dyn_cast<llvm::CallInst>(result);
+ // Look for a retain call.
+ llvm::CallInst *retainCall =
+ dyn_cast<llvm::CallInst>(result->stripPointerCasts());
if (!retainCall || retainCall->getCalledOperand() !=
CGF.CGM.getObjCEntrypoints().objc_retain)
return nullptr;
diff --git a/clang/test/CodeGenObjC/arc.m b/clang/test/CodeGenObjC/arc.m
index fb4eb3452318df5..754c339cb2b31e6 100644
--- a/clang/test/CodeGenObjC/arc.m
+++ b/clang/test/CodeGenObjC/arc.m
@@ -7,30 +7,30 @@
// RUN: %clang_cc1 -fobjc-runtime=macosx-10.7.0 -triple x86_64-apple-darwin11 -Wno-objc-root-class -Wno-incompatible-pointer-types -Wno-arc-unsafe-retained-assign -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck -check-prefix=ARC-NATIVE %s
// ARC-ALIEN: declare extern_weak void @llvm.objc.storeStrong(ptr, ptr)
-// ARC-ALIEN: declare extern_weak ptr @llvm.objc.retain(ptr returned)
-// ARC-ALIEN: declare extern_weak ptr @llvm.objc.autoreleaseReturnValue(ptr returned)
+// ARC-ALIEN: declare extern_weak ptr @llvm.objc.retain(ptr)
+// ARC-ALIEN: declare extern_weak ptr @llvm.objc.autoreleaseReturnValue(ptr)
// ARC-ALIEN: declare ptr @objc_msgSend(ptr, ptr, ...) [[NLB:#[0-9]+]]
// ARC-ALIEN: declare extern_weak void @llvm.objc.release(ptr)
-// ARC-ALIEN: declare extern_weak ptr @llvm.objc.retainAutoreleasedReturnValue(ptr returned)
+// ARC-ALIEN: declare extern_weak ptr @llvm.objc.retainAutoreleasedReturnValue(ptr)
// ARC-ALIEN: declare extern_weak ptr @llvm.objc.initWeak(ptr, ptr)
// ARC-ALIEN: declare extern_weak ptr @llvm.objc.storeWeak(ptr, ptr)
// ARC-ALIEN: declare extern_weak ptr @llvm.objc.loadWeakRetained(ptr)
// ARC-ALIEN: declare extern_weak void @llvm.objc.destroyWeak(ptr)
-// ARC-ALIEN: declare extern_weak ptr @llvm.objc.autorelease(ptr returned)
-// ARC-ALIEN: declare extern_weak ptr @llvm.objc.retainAutorelease(ptr returned)
+// ARC-ALIEN: declare extern_weak ptr @llvm.objc.autorelease(ptr)
+// ARC-ALIEN: declare extern_weak ptr @llvm.objc.retainAutorelease(ptr)
// ARC-NATIVE: declare void @llvm.objc.storeStrong(ptr, ptr)
-// ARC-NATIVE: declare ptr @llvm.objc.retain(ptr returned)
-// ARC-NATIVE: declare ptr @llvm.objc.autoreleaseReturnValue(ptr returned)
+// ARC-NATIVE: declare ptr @llvm.objc.retain(ptr)
+// ARC-NATIVE: declare ptr @llvm.objc.autoreleaseReturnValue(ptr)
// ARC-NATIVE: declare ptr @objc_msgSend(ptr, ptr, ...) [[NLB:#[0-9]+]]
// ARC-NATIVE: declare void @llvm.objc.release(ptr)
-// ARC-NATIVE: declare ptr @llvm.objc.retainAutoreleasedReturnValue(ptr returned)
+// ARC-NATIVE: declare ptr @llvm.objc.retainAutoreleasedReturnValue(ptr)
// ARC-NATIVE: declare ptr @llvm.objc.initWeak(ptr, ptr)
// ARC-NATIVE: declare ptr @llvm.objc.storeWeak(ptr, ptr)
// ARC-NATIVE: declare ptr @llvm.objc.loadWeakRetained(ptr)
// ARC-NATIVE: declare void @llvm.objc.destroyWeak(ptr)
-// ARC-NATIVE: declare ptr @llvm.objc.autorelease(ptr returned)
-// ARC-NATIVE: declare ptr @llvm.objc.retainAutorelease(ptr returned)
+// ARC-NATIVE: declare ptr @llvm.objc.autorelease(ptr)
+// ARC-NATIVE: declare ptr @llvm.objc.retainAutorelease(ptr)
// CHECK-LABEL: define{{.*}} void @test0
void test0(id x) {
diff --git a/clang/test/CodeGenObjC/convert-messages-to-runtime-calls.m b/clang/test/CodeGenObjC/convert-messages-to-runtime-calls.m
index a60c9b0feb801f5..9a5ecbc03d8ae6e 100644
--- a/clang/test/CodeGenObjC/convert-messages-to-runtime-calls.m
+++ b/clang/test/CodeGenObjC/convert-messages-to-runtime-calls.m
@@ -28,11 +28,6 @@ void test1(id x) {
// MSGS: {{call.*@objc_msgSend}}
// CALLS: {{call.*@objc_alloc}}
// CALLS: {{call.*@objc_allocWithZone}}
-
- // Note that calls to the intrinsics are not allowed for
- // retain/release/autorelease they're marked `thisreturn`, which isn't
- // guaranteed to be true for classes that define their own `-retain`, for
- // example. Be sure to keep these as normal function calls:
// CALLS: {{call.*@objc_retain}}
// CALLS: {{call.*@objc_release}}
// CALLS: {{tail call.*@objc_autorelease}}
diff --git a/llvm/include/llvm/IR/Intrinsics.td b/llvm/include/llvm/IR/Intrinsics.td
index b22da112f578fd6..80c3d8d403d9115 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -720,13 +720,11 @@ def int_gcwrite : Intrinsic<[],
// eliminate retain and releases where possible.
def int_objc_autorelease : Intrinsic<[llvm_ptr_ty],
- [llvm_ptr_ty],
- [Returned<ArgIndex<0>>]>;
+ [llvm_ptr_ty]>;
def int_objc_autoreleasePoolPop : Intrinsic<[], [llvm_ptr_ty]>;
def int_objc_autoreleasePoolPush : Intrinsic<[llvm_ptr_ty], []>;
def int_objc_autoreleaseReturnValue : Intrinsic<[llvm_ptr_ty],
- [llvm_ptr_ty],
- [Returned<ArgIndex<0>>]>;
+ [llvm_ptr_ty]>;
def int_objc_copyWeak : Intrinsic<[],
[llvm_ptr_ty,
llvm_ptr_ty]>;
@@ -743,17 +741,13 @@ def int_objc_moveWeak : Intrinsic<[],
llvm_ptr_ty]>;
def int_objc_release : Intrinsic<[], [llvm_ptr_ty]>;
def int_objc_retain : Intrinsic<[llvm_ptr_ty],
- [llvm_ptr_ty],
- [Returned<ArgIndex<0>>]>;
+ [llvm_ptr_ty]>;
def int_objc_retainAutorelease : Intrinsic<[llvm_ptr_ty],
- [llvm_ptr_ty],
- [Returned<ArgIndex<0>>]>;
+ [llvm_ptr_ty]>;
def int_objc_retainAutoreleaseReturnValue : Intrinsic<[llvm_ptr_ty],
- [llvm_ptr_ty],
- [Returned<ArgIndex<0>>]>;
+ [llvm_ptr_ty]>;
def int_objc_retainAutoreleasedReturnValue : Intrinsic<[llvm_ptr_ty],
- [llvm_ptr_ty],
- [Returned<ArgIndex<0>>]>;
+ [llvm_ptr_ty]>;
def int_objc_retainBlock : Intrinsic<[llvm_ptr_ty],
[llvm_ptr_ty]>;
def int_objc_storeStrong : Intrinsic<[],
@@ -768,8 +762,7 @@ def int_objc_clang_arc_noop_use : DefaultAttrsIntrinsic<[],
[llvm_vararg_ty],
[IntrInaccessibleMemOnly]>;
def int_objc_unsafeClaimAutoreleasedReturnValue : Intrinsic<[llvm_ptr_ty],
- [llvm_ptr_ty],
- [Returned<ArgIndex<0>>]>;
+ [llvm_ptr_ty]>;
def int_objc_retainedObject : Intrinsic<[llvm_ptr_ty],
[llvm_ptr_ty]>;
def int_objc_unretainedObject : Intrinsic<[llvm_ptr_ty],
@@ -777,8 +770,7 @@ def int_objc_unretainedObject : Intrinsic<[llvm_ptr_ty],
def int_objc_unretainedPointer : Intrinsic<[llvm_ptr_ty],
[llvm_ptr_ty]>;
def int_objc_retain_autorelease : Intrinsic<[llvm_ptr_ty],
- [llvm_ptr_ty],
- [Returned<ArgIndex<0>>]>;
+ [llvm_ptr_ty]>;
def int_objc_sync_enter : Intrinsic<[llvm_i32_ty],
[llvm_ptr_ty]>;
def int_objc_sync_exit : Intrinsic<[llvm_i32_ty],
diff --git a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
index 931830677970812..b6e8e9a8b45b9a9 100644
--- a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
+++ b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
@@ -162,16 +162,6 @@ static bool lowerObjCCall(Function &F, const char *NewFn,
CallInst::TailCallKind TCK = CI->getTailCallKind();
NewCI->setTailCallKind(std::max(TCK, OverridingTCK));
- // Transfer the 'returned' attribute from the intrinsic to the call site.
- // By applying this only to intrinsic call sites, we avoid applying it to
- // non-ARC explicit calls to things like objc_retain which have not been
- // auto-upgraded to use the intrinsics.
- unsigned Index;
- if (F.getAttributes().hasAttrSomewhere(Attribute::Returned, &Index) &&
- Index)
- NewCI->addParamAttr(Index - AttributeList::FirstArgIndex,
- Attribute::Returned);
-
if (!CI->use_empty())
CI->replaceAllUsesWith(NewCI);
CI->eraseFromParent();
diff --git a/llvm/test/Transforms/PreISelIntrinsicLowering/X86/objc-arc.ll b/llvm/test/Transforms/PreISelIntrinsicLowering/X86/objc-arc.ll
index 861c8586bed3a40..b36737f12e47714 100644
--- a/llvm/test/Transforms/PreISelIntrinsicLowering/X86/objc-arc.ll
+++ b/llvm/test/Transforms/PreISelIntrinsicLowering/X86/objc-arc.ll
@@ -9,7 +9,7 @@ declare i32 @__gxx_personality_v0(...)
define ptr @test_objc_autorelease(ptr %arg0) {
; CHECK-LABEL: test_objc_autorelease
; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = notail call ptr @objc_autorelease(ptr returned %arg0)
+; CHECK-NEXT: %0 = notail call ptr @objc_autorelease(ptr %arg0)
; CHECK-NEXT: ret ptr %0
entry:
%0 = call ptr @llvm.objc.autorelease(ptr %arg0)
@@ -39,7 +39,7 @@ entry:
define ptr @test_objc_autoreleaseReturnValue(ptr %arg0) {
; CHECK-LABEL: test_objc_autoreleaseReturnValue
; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = tail call ptr @objc_autoreleaseReturnValue(ptr returned %arg0)
+; CHECK-NEXT: %0 = tail call ptr @objc_autoreleaseReturnValue(ptr %arg0)
; CHECK-NEXT: ret ptr %0
entry:
%0 = call ptr @llvm.objc.autoreleaseReturnValue(ptr %arg0)
@@ -119,7 +119,7 @@ entry:
define ptr @test_objc_retain(ptr %arg0) {
; CHECK-LABEL: test_objc_retain
; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = tail call ptr @objc_retain(ptr returned %arg0)
+; CHECK-NEXT: %0 = tail call ptr @objc_retain(ptr %arg0)
; CHECK-NEXT: ret ptr %0
entry:
%0 = call ptr @llvm.objc.retain(ptr %arg0)
@@ -129,7 +129,7 @@ entry:
define ptr @test_objc_retainAutorelease(ptr %arg0) {
; CHECK-LABEL: test_objc_retainAutorelease
; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = call ptr @objc_retainAutorelease(ptr returned %arg0)
+; CHECK-NEXT: %0 = call ptr @objc_retainAutorelease(ptr %arg0)
; CHECK-NEXT: ret ptr %0
entry:
%0 = call ptr @llvm.objc.retainAutorelease(ptr %arg0)
@@ -139,7 +139,7 @@ entry:
define ptr @test_objc_retainAutoreleaseReturnValue(ptr %arg0) {
; CHECK-LABEL: test_objc_retainAutoreleaseReturnValue
; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = tail call ptr @objc_retainAutoreleaseReturnValue(ptr returned %arg0)
+; CHECK-NEXT: %0 = tail call ptr @objc_retainAutoreleaseReturnValue(ptr %arg0)
; CHECK-NEXT: ret ptr %0
entry:
%0 = tail call ptr @llvm.objc.retainAutoreleaseReturnValue(ptr %arg0)
@@ -149,7 +149,7 @@ entry:
define ptr @test_objc_retainAutoreleasedReturnValue(ptr %arg0) {
; CHECK-LABEL: test_objc_retainAutoreleasedReturnValue
; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = tail call ptr @objc_retainAutoreleasedReturnValue(ptr returned %arg0)
+; CHECK-NEXT: %0 = tail call ptr @objc_retainAutoreleasedReturnValue(ptr %arg0)
; CHECK-NEXT: ret ptr %0
entry:
%0 = call ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %arg0)
@@ -213,7 +213,7 @@ entry:
define ptr @test_objc_unsafeClaimAutoreleasedReturnValue(ptr %arg0) {
; CHECK-LABEL: test_objc_unsafeClaimAutoreleasedReturnValue
; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = tail call ptr @objc_unsafeClaimAutoreleasedReturnValue(ptr returned %arg0)
+; CHECK-NEXT: %0 = tail call ptr @objc_unsafeClaimAutoreleasedReturnValue(ptr %arg0)
; CHECK-NEXT: ret ptr %0
entry:
%0 = call ptr @llvm.objc.unsafeClaimAutoreleasedReturnValue(ptr %arg0)
@@ -260,7 +260,7 @@ entry:
define ptr @test_objc_retain_autorelease(ptr %arg0) {
; CHECK-LABEL: test_objc_retain_autorelease
; CHECK-NEXT: entry
-; CHECK-NEXT: %0 = call ptr @objc_retain_autorelease(ptr returned %arg0)
+; CHECK-NEXT: %0 = call ptr @objc_retain_autorelease(ptr %arg0)
; CHECK-NEXT: ret ptr %0
entry:
%0 = call ptr @llvm.objc.retain.autorelease(ptr %arg0)
More information about the llvm-commits
mailing list