summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaStmt.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2011-12-28 19:48:30 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2011-12-28 19:48:30 +0000
commit5fab0c9e1ad172c0db6cc9f3169666e49b7864b6 (patch)
treea5682a764875540c534db1a6460792d4a599c6a3 /clang/lib/Sema/SemaStmt.cpp
parente4a84c4f1f17a1e9b7f0e9a75f9d8ee1824feb33 (diff)
downloadbcm5719-llvm-5fab0c9e1ad172c0db6cc9f3169666e49b7864b6.tar.gz
bcm5719-llvm-5fab0c9e1ad172c0db6cc9f3169666e49b7864b6.zip
Small refactoring and simplification of constant evaluation and some of its
clients. No functionality change. llvm-svn: 147318
Diffstat (limited to 'clang/lib/Sema/SemaStmt.cpp')
-rw-r--r--clang/lib/Sema/SemaStmt.cpp18
1 files changed, 6 insertions, 12 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 2325711b29c..d79218d8491 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -16,7 +16,6 @@
#include "clang/Sema/ScopeInfo.h"
#include "clang/Sema/Initialization.h"
#include "clang/Sema/Lookup.h"
-#include "clang/AST/APValue.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/CharUnits.h"
#include "clang/AST/DeclObjC.h"
@@ -664,20 +663,15 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch,
// condition is constant.
llvm::APSInt ConstantCondValue;
bool HasConstantCond = false;
- bool ShouldCheckConstantCond = false;
if (!HasDependentValue && !TheDefaultStmt) {
- Expr::EvalResult Result;
HasConstantCond
- = CondExprBeforePromotion->EvaluateAsRValue(Result, Context);
- if (HasConstantCond) {
- assert(Result.Val.isInt() && "switch condition evaluated to non-int");
- ConstantCondValue = Result.Val.getInt();
- ShouldCheckConstantCond = true;
-
- assert(ConstantCondValue.getBitWidth() == CondWidth &&
- ConstantCondValue.isSigned() == CondIsSigned);
- }
+ = CondExprBeforePromotion->EvaluateAsInt(ConstantCondValue, Context,
+ Expr::SE_AllowSideEffects);
+ assert(!HasConstantCond ||
+ (ConstantCondValue.getBitWidth() == CondWidth &&
+ ConstantCondValue.isSigned() == CondIsSigned));
}
+ bool ShouldCheckConstantCond = HasConstantCond;
// Sort all the scalar case values so we can easily detect duplicates.
std::stable_sort(CaseVals.begin(), CaseVals.end(), CmpCaseVals);
OpenPOWER on IntegriCloud