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

Commit

Permalink
[SimplifyCFG] Don't kill empty cleanuppads with multiple uses
Browse files Browse the repository at this point in the history
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
  • Loading branch information
majnemer committed Jun 4, 2016
1 parent c6b77e5 commit 8c4b617
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Transforms/Utils/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3424,6 +3424,11 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI) {
// This isn't an empty cleanup.
return false;

// We cannot kill the pad if it has multiple uses. This typically arises
// from unreachable basic blocks.
if (!CPInst->hasOneUse())
return false;

// Check that there are no other instructions except for benign intrinsics.
BasicBlock::iterator I = CPInst->getIterator(), E = RI->getIterator();
while (++I != E) {
Expand Down
24 changes: 24 additions & 0 deletions test/Transforms/SimplifyCFG/empty-cleanuppad.ll
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,30 @@ try.cont:
ret i32 0
}

; CHECK-LABEL: define void @f10(
define void @f10(i32 %V) personality i32 (...)* @__CxxFrameHandler3 {
entry:
invoke void @g()
to label %unreachable unwind label %cleanup
; CHECK: call void @g()
; CHECK-NEXT: unreachable

unreachable:
unreachable

cleanup:
%cp = cleanuppad within none []
switch i32 %V, label %cleanupret1 [
i32 0, label %cleanupret2
]

cleanupret1:
cleanupret from %cp unwind to caller

cleanupret2:
cleanupret from %cp unwind to caller
}

%struct.S = type { i8 }
%struct.S2 = type { i8 }
declare void @"\01??1S2@@QEAA@XZ"(%struct.S2*)
Expand Down

0 comments on commit 8c4b617

Please sign in to comment.