[Attributor] Fix for a crash on RAUW when rewriting function signature

Reviewers: jdoerfert, sstefan1, uenoku

Reviewed By: uenoku

Subscribers: hiraditya, uenoku, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D79680
This commit is contained in:
Sergey Dmitriev 2020-05-11 08:05:51 -07:00
parent dcc5ff3bc2
commit 3df40007e6
2 changed files with 21 additions and 4 deletions

View File

@ -1596,7 +1596,8 @@ ChangeStatus Attributor::rewriteFunctionSignatures(
CallBase &NewCB = *CallSitePair.second;
ModifiedFns.insert(OldCB.getFunction());
CGUpdater.replaceCallSite(OldCB, NewCB);
OldCB.replaceAllUsesWith(&NewCB);
if (!OldCB.use_empty())
OldCB.replaceAllUsesWith(&NewCB);
OldCB.eraseFromParent();
}

View File

@ -1,7 +1,8 @@
; RUN: opt -attributor -S %s | FileCheck %s
; RUN: opt -passes=attributor -S %s | FileCheck %s
@var = internal global [1 x i32] undef
@var1 = internal global [1 x i32] undef
@var2 = internal global i32 0
; CHECK-LABEL: define i32 addrspace(1)* @foo(i32 addrspace(4)* nofree readnone %arg)
define i32 addrspace(1)* @foo(i32 addrspace(4)* %arg) {
@ -11,13 +12,28 @@ entry:
}
define i32* @func1() {
%ptr = call i32* @func1a([1 x i32]* @var)
%ptr = call i32* @func1a([1 x i32]* @var1)
ret i32* %ptr
}
; CHECK-LABEL: define internal nonnull align 4 dereferenceable(4) i32* @func1a()
; CHECK-NEXT: ret i32* getelementptr inbounds ([1 x i32], [1 x i32]* @var, i32 0, i32 0)
; CHECK-NEXT: ret i32* getelementptr inbounds ([1 x i32], [1 x i32]* @var1, i32 0, i32 0)
define internal i32* @func1a([1 x i32]* %arg) {
%ptr = getelementptr inbounds [1 x i32], [1 x i32]* %arg, i64 0, i64 0
ret i32* %ptr
}
define internal void @func2a(i32* %0) {
store i32 0, i32* %0
ret void
}
; CHECK-LABEL: define i32 @func2()
; CHECK-NEXT: tail call void @func2a()
; CHECK-NEXT: %1 = load i32, i32* @var2, align 4
; CHECK-NEXT: ret i32 %1
define i32 @func2() {
%1 = tail call i32 (i32*, ...) bitcast (void (i32*)* @func2a to i32 (i32*, ...)*)(i32* @var2)
%2 = load i32, i32* @var2
ret i32 %2
}