aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-09-21 18:15:22 +0000
committerChris Lattner <sabre@nondot.org>2007-09-21 18:15:22 +0000
commit764a7ce5217f9569e100a3445f47496ee82daf86 (patch)
treecd356965f207ab767535d36b64de134d2884d6ed
parent894c57f565869b26a65436d250a9ca7a04d2abe0 (diff)
Make case sorting deterministic by not depending on pointer
values. Patch mostly by Gabor Greif for PR1682. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42203 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--Sema/SemaStmt.cpp19
-rw-r--r--clang.xcodeproj/project.pbxproj1
-rw-r--r--include/clang/AST/Stmt.h2
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]; }