Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 8c4b617

Browse files
committed
[SimplifyCFG] Don't kill empty cleanuppads with multiple uses
A basic block could contain: %cp = cleanuppad [] cleanupret from %cp unwind to caller This basic block is empty and is thus a candidate for removal. However, there can be other uses of %cp outside of this basic block. This is only possible in unreachable blocks. Make our transform more correct by checking that the pad has a single user before removing the BB. This fixes PR28005. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271816 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent c6b77e5 commit 8c4b617

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3424,6 +3424,11 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI) {
34243424
// This isn't an empty cleanup.
34253425
return false;
34263426

3427+
// We cannot kill the pad if it has multiple uses. This typically arises
3428+
// from unreachable basic blocks.
3429+
if (!CPInst->hasOneUse())
3430+
return false;
3431+
34273432
// Check that there are no other instructions except for benign intrinsics.
34283433
BasicBlock::iterator I = CPInst->getIterator(), E = RI->getIterator();
34293434
while (++I != E) {

test/Transforms/SimplifyCFG/empty-cleanuppad.ll

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,30 @@ try.cont:
434434
ret i32 0
435435
}
436436

437+
; CHECK-LABEL: define void @f10(
438+
define void @f10(i32 %V) personality i32 (...)* @__CxxFrameHandler3 {
439+
entry:
440+
invoke void @g()
441+
to label %unreachable unwind label %cleanup
442+
; CHECK: call void @g()
443+
; CHECK-NEXT: unreachable
444+
445+
unreachable:
446+
unreachable
447+
448+
cleanup:
449+
%cp = cleanuppad within none []
450+
switch i32 %V, label %cleanupret1 [
451+
i32 0, label %cleanupret2
452+
]
453+
454+
cleanupret1:
455+
cleanupret from %cp unwind to caller
456+
457+
cleanupret2:
458+
cleanupret from %cp unwind to caller
459+
}
460+
437461
%struct.S = type { i8 }
438462
%struct.S2 = type { i8 }
439463
declare void @"\01??1S2@@QEAA@XZ"(%struct.S2*)

0 commit comments

Comments
 (0)