summaryrefslogtreecommitdiffstats
path: root/clang/Sema/SemaStmt.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-08-23 17:48:14 +0000
committerChris Lattner <sabre@nondot.org>2007-08-23 17:48:14 +0000
commitf81460f99c250fb758220ec0c40835d1630ea398 (patch)
treef1c5a0d7aaf3947e07af6f7c6149f24fdf553eee /clang/Sema/SemaStmt.cpp
parent9ee3bcf81c0ecb9a7c9600437bbc5fc0dc1f5972 (diff)
downloadbcm5719-llvm-f81460f99c250fb758220ec0c40835d1630ea398.tar.gz
bcm5719-llvm-f81460f99c250fb758220ec0c40835d1630ea398.zip
detect and diagnose empty case ranges:
switch.c:16:8: warning: empty case range specified case 100 ... 99: ; // expected-warning {{empty case range}} ^~~~~~~~~~ llvm-svn: 41328
Diffstat (limited to 'clang/Sema/SemaStmt.cpp')
-rw-r--r--clang/Sema/SemaStmt.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/clang/Sema/SemaStmt.cpp b/clang/Sema/SemaStmt.cpp
index ee3a8e6a7fe..6a8c18ced65 100644
--- a/clang/Sema/SemaStmt.cpp
+++ b/clang/Sema/SemaStmt.cpp
@@ -298,7 +298,7 @@ Sema::FinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch, ExprTy *Body) {
// Scan the ranges, computing the high values and removing empty ranges.
std::vector<llvm::APSInt> HiVals;
- for (unsigned i = 0, e = CaseVals.size(); i != e; ++i) {
+ for (unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
CaseStmt *CR = CaseRanges[i].second;
llvm::APSInt HiVal(32);
CR->getRHS()->isIntegerConstantExpr(HiVal, Context);
@@ -308,9 +308,15 @@ Sema::FinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch, ExprTy *Body) {
CR->getRHS()->getLocStart(),
diag::warn_case_value_overflow);
- // FIXME: if the low value is bigger than the high value, the case is
- // empty: emit "empty range specified" warning and drop it.
-
+ // If the low value is bigger than the high value, the case is empty.
+ if (CaseRanges[i].first > HiVal) {
+ Diag(CR->getLHS()->getLocStart(), diag::warn_case_empty_range,
+ SourceRange(CR->getLHS()->getLocStart(),
+ CR->getRHS()->getLocEnd()));
+ CaseRanges.erase(CaseRanges.begin()+i);
+ --i, --e;
+ continue;
+ }
HiVals.push_back(HiVal);
}
OpenPOWER on IntegriCloud