Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 9b74379

Browse files
majnemerarielb1
authored andcommitted
[SimplifyCFG] Correctly test for unconditional branches in GetCaseResults
GetCaseResults assumed that a terminator with one successor was an unconditional branch. This is not necessarily the case, it could be a cleanupret. Strengthen the check by querying whether or not the terminator is exceptional. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283517 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 3e03f73 commit 9b74379

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

Diff for: lib/Transforms/Utils/SimplifyCFG.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4228,7 +4228,7 @@ GetCaseResults(SwitchInst *SI, ConstantInt *CaseVal, BasicBlock *CaseDest,
42284228
++I) {
42294229
if (TerminatorInst *T = dyn_cast<TerminatorInst>(I)) {
42304230
// If the terminator is a simple branch, continue to the next block.
4231-
if (T->getNumSuccessors() != 1)
4231+
if (T->getNumSuccessors() != 1 || T->isExceptional())
42324232
return false;
42334233
Pred = CaseDest;
42344234
CaseDest = T->getSuccessor(0);

Diff for: test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll

+60
Original file line numberDiff line numberDiff line change
@@ -1334,3 +1334,63 @@ cleanup4:
13341334
br label %while.body
13351335
}
13361336

1337+
declare void @throw(i1)
1338+
1339+
define void @wineh_test(i64 %val) personality i32 (...)* @__CxxFrameHandler3 {
1340+
entry:
1341+
invoke void @throw(i1 false)
1342+
to label %unreachable unwind label %cleanup1
1343+
1344+
unreachable:
1345+
unreachable
1346+
1347+
cleanup1:
1348+
%cleanuppad1 = cleanuppad within none []
1349+
switch i64 %val, label %cleanupdone2 [
1350+
i64 0, label %cleanupdone1
1351+
i64 1, label %cleanupdone1
1352+
i64 6, label %cleanupdone1
1353+
]
1354+
1355+
cleanupdone1:
1356+
cleanupret from %cleanuppad1 unwind label %cleanup2
1357+
1358+
cleanupdone2:
1359+
cleanupret from %cleanuppad1 unwind label %cleanup2
1360+
1361+
cleanup2:
1362+
%phi = phi i1 [ true, %cleanupdone1 ], [ false, %cleanupdone2 ]
1363+
%cleanuppad2 = cleanuppad within none []
1364+
call void @throw(i1 %phi) [ "funclet"(token %cleanuppad2) ]
1365+
unreachable
1366+
}
1367+
1368+
; CHECK-LABEL: @wineh_test(
1369+
; CHECK: entry:
1370+
; CHECK: invoke void @throw(i1 false)
1371+
; CHECK: to label %[[unreachable:.*]] unwind label %[[cleanup1:.*]]
1372+
1373+
; CHECK: [[unreachable]]:
1374+
; CHECK: unreachable
1375+
1376+
; CHECK: [[cleanup1]]:
1377+
; CHECK: %[[cleanuppad1:.*]] = cleanuppad within none []
1378+
; CHECK: switch i64 %val, label %[[cleanupdone2:.*]] [
1379+
; CHECK: i64 0, label %[[cleanupdone1:.*]]
1380+
; CHECK: i64 1, label %[[cleanupdone1]]
1381+
; CHECK: i64 6, label %[[cleanupdone1]]
1382+
; CHECK: ]
1383+
1384+
; CHECK: [[cleanupdone1]]:
1385+
; CHECK: cleanupret from %[[cleanuppad1]] unwind label %[[cleanup2:.*]]
1386+
1387+
; CHECK: [[cleanupdone2]]:
1388+
; CHECK: cleanupret from %[[cleanuppad1]] unwind label %[[cleanup2]]
1389+
1390+
; CHECK: [[cleanup2]]:
1391+
; CHECK: %[[phi:.*]] = phi i1 [ true, %[[cleanupdone1]] ], [ false, %[[cleanupdone2]] ]
1392+
; CHECK: %[[cleanuppad2:.*]] = cleanuppad within none []
1393+
; CHECK: call void @throw(i1 %[[phi]]) [ "funclet"(token %[[cleanuppad2]]) ]
1394+
; CHECK: unreachable
1395+
1396+
declare i32 @__CxxFrameHandler3(...)

0 commit comments

Comments
 (0)