fix a segfault in cases where there are no cases.
llvm-svn: 41317
This commit is contained in:
parent
97cdac8d19
commit
fcb920d32b
|
@ -274,16 +274,18 @@ Sema::FinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch, ExprTy *Body) {
|
||||||
// Sort all the scalar case values so we can easily detect duplicates.
|
// Sort all the scalar case values so we can easily detect duplicates.
|
||||||
std::stable_sort(CaseVals.begin(), CaseVals.end());
|
std::stable_sort(CaseVals.begin(), CaseVals.end());
|
||||||
|
|
||||||
for (unsigned i = 0, e = CaseVals.size()-1; i != e; ++i) {
|
if (!CaseVals.empty()) {
|
||||||
if (CaseVals[i].first == CaseVals[i+1].first) {
|
for (unsigned i = 0, e = CaseVals.size()-1; i != e; ++i) {
|
||||||
// If we have a duplicate, report it.
|
if (CaseVals[i].first == CaseVals[i+1].first) {
|
||||||
Diag(CaseVals[i+1].second->getLHS()->getLocStart(),
|
// If we have a duplicate, report it.
|
||||||
diag::err_duplicate_case, CaseVals[i].first.toString());
|
Diag(CaseVals[i+1].second->getLHS()->getLocStart(),
|
||||||
Diag(CaseVals[i].second->getLHS()->getLocStart(),
|
diag::err_duplicate_case, CaseVals[i].first.toString());
|
||||||
diag::err_duplicate_case_prev);
|
Diag(CaseVals[i].second->getLHS()->getLocStart(),
|
||||||
// FIXME: We really want to remove the bogus case stmt from the substmt,
|
diag::err_duplicate_case_prev);
|
||||||
// but we have no way to do this right now.
|
// FIXME: We really want to remove the bogus case stmt from the substmt,
|
||||||
CaseListIsErroneous = true;
|
// but we have no way to do this right now.
|
||||||
|
CaseListIsErroneous = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,3 +15,7 @@ void foo(int X) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test3(void) {
|
||||||
|
switch (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue