[llvm] 3df4000 - [Attributor] Fix for a crash on RAUW when rewriting function signature
Sergey Dmitriev via llvm-commits
llvm-commits at lists.llvm.org
Mon May 11 08:21:15 PDT 2020
Author: Sergey Dmitriev
Date: 2020-05-11T08:06:19-07:00
New Revision: 3df40007e6317955176dff0fa9e0b029dc4a11d1
URL: https://github.com/llvm/llvm-project/commit/3df40007e6317955176dff0fa9e0b029dc4a11d1
DIFF: https://github.com/llvm/llvm-project/commit/3df40007e6317955176dff0fa9e0b029dc4a11d1.diff
LOG: [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
Added:
llvm/test/Transforms/Attributor/misc_crash.ll
Modified:
llvm/lib/Transforms/IPO/Attributor.cpp
Removed:
llvm/test/Transforms/Attributor/returned_crash.ll
################################################################################
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 421e47737011..e1189239d3a0 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -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();
}
diff --git a/llvm/test/Transforms/Attributor/returned_crash.ll b/llvm/test/Transforms/Attributor/misc_crash.ll
similarity index 55%
rename from llvm/test/Transforms/Attributor/returned_crash.ll
rename to llvm/test/Transforms/Attributor/misc_crash.ll
index 6b4b9a32d79e..476ebbee2048 100644
--- a/llvm/test/Transforms/Attributor/returned_crash.ll
+++ b/llvm/test/Transforms/Attributor/misc_crash.ll
@@ -1,7 +1,8 @@
; RUN: opt -attributor -S %s | FileCheck %s
; RUN: opt -passes=attributor -S %s | FileCheck %s
- at var = internal global [1 x i32] undef
+ at var1 = internal global [1 x i32] undef
+ at 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
+}
More information about the llvm-commits
mailing list