diff options
-rw-r--r-- | Sema/SemaStmt.cpp | 19 | ||||
-rw-r--r-- | clang.xcodeproj/project.pbxproj | 1 | ||||
-rw-r--r-- | include/clang/AST/Stmt.h | 2 |
3 files changed, 19 insertions, 3 deletions
diff --git a/Sema/SemaStmt.cpp b/Sema/SemaStmt.cpp index 0522996a55..653a0ab5b9 100644 --- a/Sema/SemaStmt.cpp +++ b/Sema/SemaStmt.cpp @@ -259,8 +259,23 @@ namespace { }; } +/// CmpCaseVals - Comparison predicate for sorting case values. +/// +static bool CmpCaseVals(const std::pair<llvm::APSInt, CaseStmt*>& lhs, + const std::pair<llvm::APSInt, CaseStmt*>& rhs) { + if (lhs.first < rhs.first) + return true; + + if (lhs.first == rhs.first && + lhs.second->getCaseLoc().getRawEncoding() + < rhs.second->getCaseLoc().getRawEncoding()) + return true; + return false; +} + Action::StmtResult -Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch, ExprTy *Body) { +Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch, + ExprTy *Body) { Stmt *BodyStmt = (Stmt*)Body; SwitchStmt *SS = SwitchStack.back(); @@ -335,7 +350,7 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch, ExprTy *Bo } // 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(), CmpCaseVals); if (!CaseVals.empty()) { for (unsigned i = 0, e = CaseVals.size()-1; i != e; ++i) { diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj index 443e9245e0..5f0ee39dab 100644 --- a/clang.xcodeproj/project.pbxproj +++ b/clang.xcodeproj/project.pbxproj @@ -725,7 +725,6 @@ 08FB7793FE84155DC02AAC07 /* Project object */ = { isa = PBXProject; buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */; - compatibilityVersion = "Xcode 2.4"; hasScannedForEncodings = 1; mainGroup = 08FB7794FE84155DC02AAC07 /* clang */; projectDirPath = ""; diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index cc1c1cf6e3..a346fdc33f 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -258,6 +258,8 @@ public: CaseLoc = caseLoc; } + SourceLocation getCaseLoc() const { return CaseLoc; } + Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); } Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); } Stmt *getSubStmt() { return SubExprs[SUBSTMT]; } |