diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-10-10 18:28:20 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-10-10 18:28:20 +0000 |
commit | caf3390d449ccc4a2eb97958dd3d456d1ea4bf90 (patch) | |
tree | ff8b87a69b97998ade8e050f2b93d9b31b1a6c6c /clang/lib/Sema/SemaStmt.cpp | |
parent | 47aac5104302121ba64975cd4b51e27ef621131e (diff) | |
download | bcm5719-llvm-caf3390d449ccc4a2eb97958dd3d456d1ea4bf90.tar.gz bcm5719-llvm-caf3390d449ccc4a2eb97958dd3d456d1ea4bf90.zip |
Constant expression evaluation refactoring:
- Remodel Expr::EvaluateAsInt to behave like the other EvaluateAs* functions,
and add Expr::EvaluateKnownConstInt to capture the current fold-or-assert
behaviour.
- Factor out evaluation of bitfield bit widths.
- Fix a few places which would evaluate an expression twice: once to determine
whether it is a constant expression, then again to get the value.
llvm-svn: 141561
Diffstat (limited to 'clang/lib/Sema/SemaStmt.cpp')
-rw-r--r-- | clang/lib/Sema/SemaStmt.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index b30be82ceec..7abfdd09de5 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -626,7 +626,7 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, break; } - llvm::APSInt LoVal = Lo->EvaluateAsInt(Context); + llvm::APSInt LoVal = Lo->EvaluateKnownConstInt(Context); // Convert the value to the same width/sign as the condition. ConvertIntegerToTypeWarnOnOverflow(LoVal, CondWidth, CondIsSigned, @@ -705,7 +705,7 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, llvm::APSInt &LoVal = CaseRanges[i].first; CaseStmt *CR = CaseRanges[i].second; Expr *Hi = CR->getRHS(); - llvm::APSInt HiVal = Hi->EvaluateAsInt(Context); + llvm::APSInt HiVal = Hi->EvaluateKnownConstInt(Context); // Convert the value to the same width/sign as the condition. ConvertIntegerToTypeWarnOnOverflow(HiVal, CondWidth, CondIsSigned, @@ -845,7 +845,8 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, << ED->getDeclName(); } - llvm::APSInt Hi = RI->second->getRHS()->EvaluateAsInt(Context); + llvm::APSInt Hi = + RI->second->getRHS()->EvaluateKnownConstInt(Context); AdjustAPSInt(Hi, CondWidth, CondIsSigned); while (EI != EIend && EI->first < Hi) EI++; @@ -873,7 +874,8 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, // Drop unneeded case ranges for (; RI != CaseRanges.end(); RI++) { - llvm::APSInt Hi = RI->second->getRHS()->EvaluateAsInt(Context); + llvm::APSInt Hi = + RI->second->getRHS()->EvaluateKnownConstInt(Context); AdjustAPSInt(Hi, CondWidth, CondIsSigned); if (EI->first <= Hi) break; |