@@ -914,9 +914,7 @@ std::pair<CaseStmt *, CaseStmt *> ASTScopeImpl::lookupFallthroughSourceAndDest(
914
914
ASTScopeAssert (innermost->getWasExpanded (),
915
915
" If looking in a scope, it must have been expanded." );
916
916
917
- // Look for the enclosing case statement and its 'switch' statement.
918
- CaseStmt *fallthroughSource = nullptr ;
919
- SwitchStmt *switchStmt = nullptr ;
917
+ // Look for the enclosing case statement of a 'switch'.
920
918
for (auto scope = innermost; scope && !scope->isLabeledStmtLookupTerminator ();
921
919
scope = scope->getParent ().getPtrOrNull ()) {
922
920
// If we have a case statement, record it.
@@ -926,34 +924,12 @@ std::pair<CaseStmt *, CaseStmt *> ASTScopeImpl::lookupFallthroughSourceAndDest(
926
924
// If we've found the first case statement of a switch, record it as the
927
925
// fallthrough source. do-catch statements don't support fallthrough.
928
926
if (auto caseStmt = dyn_cast<CaseStmt>(stmt.get ())) {
929
- if (!fallthroughSource &&
930
- caseStmt->getParentKind () == CaseParentKind::Switch)
931
- fallthroughSource = caseStmt;
927
+ if (caseStmt->getParentKind () == CaseParentKind::Switch)
928
+ return { caseStmt, caseStmt->findNextCaseStmt () };
932
929
933
930
continue ;
934
931
}
935
-
936
- // If we've found the first switch statement, record it and we're done.
937
- switchStmt = dyn_cast<SwitchStmt>(stmt.get ());
938
- if (switchStmt)
939
- break ;
940
932
}
941
933
942
- // If we don't have both a fallthrough source and a switch statement
943
- // enclosing it, the 'fallthrough' statement is ill-formed.
944
- if (!fallthroughSource || !switchStmt)
945
- return { nullptr , nullptr };
946
-
947
- // Find this case in the list of cases for the switch. If we don't find it
948
- // here, it means that the case isn't directly nested inside the switch, so
949
- // the case and fallthrough are both ill-formed.
950
- auto caseIter = llvm::find (switchStmt->getCases (), fallthroughSource);
951
- if (caseIter == switchStmt->getCases ().end ())
952
- return { nullptr , nullptr };
953
-
954
- // Move along to the next case. This is the fallthrough destination.
955
- ++caseIter;
956
- auto fallthroughDest = caseIter == switchStmt->getCases ().end () ? nullptr
957
- : *caseIter;
958
- return { fallthroughSource, fallthroughDest };
934
+ return { nullptr , nullptr };
959
935
}
0 commit comments