Skip to content

ObjCARC: Fix regression from using ConstantData uselists #139609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ bool ProvenanceAnalysis::relatedPHI(const PHINode *A,
/// Test if the value of P, or any value covered by its provenance, is ever
/// stored within the function (not counting callees).
static bool IsStoredObjCPointer(const Value *P) {
if (!P->hasUseList())
return true; // Assume the worst for a constant pointer.

SmallPtrSet<const Value *, 8> Visited;
SmallVector<const Value *, 8> Worklist;
Worklist.push_back(P);
Expand Down
42 changes: 42 additions & 0 deletions llvm/test/Transforms/ObjCARC/pr138961-regression.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt -S -passes=objc-arc < %s | FileCheck %s

target triple = "x86_64-apple-macosx11.0.0"

declare ptr @llvm.objc.retain(ptr returned) #0
declare void @llvm.objc.release(ptr) #0

declare ptr @foo(ptr)

define i1 @_ZN8GrMtlGpu20readOrTransferPixelsEP9GrSurface7SkIRect11GrColorTypePU19objcproto9MTLBuffer11objc_objectmmm(ptr %this) #1 {
; CHECK-LABEL: define i1 @_ZN8GrMtlGpu20readOrTransferPixelsEP9GrSurface7SkIRect11GrColorTypePU19objcproto9MTLBuffer11objc_objectmmm(
; CHECK-SAME: ptr [[THIS:%.*]]) #[[ATTR1:[0-9]+]] {
; CHECK-NEXT: [[ENTRY:.*]]:
; CHECK-NEXT: [[RETAIN:%.*]] = tail call ptr @llvm.objc.retain(ptr [[THIS]]) #[[ATTR0:[0-9]+]]
; CHECK-NEXT: br i1 false, label %[[CLEANUP66:.*]], label %[[IF_END30:.*]]
; CHECK: [[IF_END30]]:
; CHECK-NEXT: [[LD_PTR:%.*]] = load ptr, ptr [[THIS]], align 8
; CHECK-NEXT: call void @foo(ptr [[LD_PTR]])
; CHECK-NEXT: br label %[[CLEANUP66]]
; CHECK: [[CLEANUP66]]:
; CHECK-NEXT: [[MTLTEXTURE_1103:%.*]] = phi ptr [ null, %[[ENTRY]] ], [ [[THIS]], %[[IF_END30]] ]
; CHECK-NEXT: tail call void @llvm.objc.release(ptr [[MTLTEXTURE_1103]]) #[[ATTR0]]
; CHECK-NEXT: ret i1 false
;
entry:
%retain = tail call ptr @llvm.objc.retain(ptr %this)
br i1 false, label %cleanup66, label %if.end30

if.end30: ; preds = %entry
%ld.ptr = load ptr, ptr %this, align 8
call void @foo(ptr %ld.ptr)
br label %cleanup66

cleanup66: ; preds = %if.end30, %entry
%mtlTexture.1103 = phi ptr [ null, %entry ], [ %this, %if.end30 ]
tail call void @llvm.objc.release(ptr %mtlTexture.1103)
ret i1 false
}

attributes #0 = { nounwind }
attributes #1 = { null_pointer_is_valid }