Skip to content

Commit 32f5ee8

Browse files
committed
[Attributor] Fixup block addresses after rewriting function signature
Reviewers: jdoerfert, sstefan1, uenoku Reviewed By: jdoerfert Subscribers: hiraditya, uenoku, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D79801
1 parent 6c29073 commit 32f5ee8

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

llvm/lib/Transforms/IPO/Attributor.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,14 @@ ChangeStatus Attributor::rewriteFunctionSignatures(
15041504
NewFn->getBasicBlockList().splice(NewFn->begin(),
15051505
OldFn->getBasicBlockList());
15061506

1507+
// Fixup block addresses to reference new function.
1508+
SmallVector<BlockAddress *, 8u> BlockAddresses;
1509+
for (User *U : OldFn->users())
1510+
if (auto *BA = dyn_cast<BlockAddress>(U))
1511+
BlockAddresses.push_back(BA);
1512+
for (auto *BA : BlockAddresses)
1513+
BA->replaceAllUsesWith(BlockAddress::get(NewFn, BA->getBasicBlock()));
1514+
15071515
// Set of all "call-like" instructions that invoke the old function mapped
15081516
// to their new replacements.
15091517
SmallVector<std::pair<CallBase *, CallBase *>, 8> CallSitePairs;

llvm/test/Transforms/Attributor/misc_crash.ll

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,36 @@ ret_bb:
7575
%2 = load i32, i32* @var2
7676
ret i32 %2
7777
}
78+
79+
define void @func4() {
80+
; CHECK-LABEL: define {{[^@]+}}@func4
81+
; CHECK-NEXT: call void @func5()
82+
; CHECK-NEXT: ret void
83+
;
84+
call void @func5(i32 0)
85+
ret void
86+
}
87+
88+
define internal void @func5(i32 %0) {
89+
; CHECK-LABEL: define {{[^@]+}}@func5
90+
; CHECK-NEXT: [[TMP1:%.*]] = alloca i8*
91+
; CHECK-NEXT: br label %block
92+
; CHECK: block:
93+
; CHECK-NEXT: store i8* blockaddress(@func5, %block), i8** [[TMP1]]
94+
; CHECK-NEXT: [[TMP2:%.*]] = load i8*, i8** [[TMP1]]
95+
; CHECK-NEXT: call void @func6(i8* [[TMP2]])
96+
; CHECK-NEXT: ret void
97+
;
98+
%tmp = alloca i8*
99+
br label %block
100+
101+
block:
102+
store i8* blockaddress(@func5, %block), i8** %tmp
103+
%addr = load i8*, i8** %tmp
104+
call void @func6(i8* %addr)
105+
ret void
106+
}
107+
108+
; CHECK-LABEL: declare {{[^@]+}}@func6
109+
; CHECK-SAME: (i8*)
110+
declare void @func6(i8*)

0 commit comments

Comments
 (0)