summaryrefslogtreecommitdiffstats
path: root/clang/Sema/SemaStmt.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-01-16 19:17:22 +0000
committerChris Lattner <sabre@nondot.org>2008-01-16 19:17:22 +0000
commita65e1f3b317643fa24a9d73a2d879244effc26e7 (patch)
treea2ec92b739b2ff1c6ead7028b3b602047c759222 /clang/Sema/SemaStmt.cpp
parent45b985c664ac7cee9dc13c72f5fdebe999e978a0 (diff)
downloadbcm5719-llvm-a65e1f3b317643fa24a9d73a2d879244effc26e7.tar.gz
bcm5719-llvm-a65e1f3b317643fa24a9d73a2d879244effc26e7.zip
Move promoteExprToType from being a static method in SemaExpr.cpp to being
a method named ImpCastExprToType in Sema. Use this method to insert implicit casts for case statements from their operand type to the condition type of the switch. This fixes a crash on test/CodeGen/statements.c, reported by Eli Friedman. llvm-svn: 46083
Diffstat (limited to 'clang/Sema/SemaStmt.cpp')
-rw-r--r--clang/Sema/SemaStmt.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/clang/Sema/SemaStmt.cpp b/clang/Sema/SemaStmt.cpp
index 4cad4a9f669..b8483866f5b 100644
--- a/clang/Sema/SemaStmt.cpp
+++ b/clang/Sema/SemaStmt.cpp
@@ -346,13 +346,19 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch,
// We already verified that the expression has a i-c-e value (C99
// 6.8.4.2p3) - get that value now.
llvm::APSInt LoVal(32);
- CS->getLHS()->isIntegerConstantExpr(LoVal, Context);
+ Expr *Lo = CS->getLHS();
+ Lo->isIntegerConstantExpr(LoVal, Context);
// Convert the value to the same width/sign as the condition.
ConvertIntegerToTypeWarnOnOverflow(LoVal, CondWidth, CondIsSigned,
CS->getLHS()->getLocStart(),
diag::warn_case_value_overflow);
+ // If the LHS is not the same type as the condition, insert an implicit
+ // cast.
+ ImpCastExprToType(Lo, CondType);
+ CS->setLHS(Lo);
+
// If this is a case range, remember it in CaseRanges, otherwise CaseVals.
if (CS->getRHS())
CaseRanges.push_back(std::make_pair(LoVal, CS));
@@ -391,13 +397,19 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch,
for (unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
CaseStmt *CR = CaseRanges[i].second;
llvm::APSInt HiVal(32);
- CR->getRHS()->isIntegerConstantExpr(HiVal, Context);
+ Expr *Hi = CR->getRHS();
+ Hi->isIntegerConstantExpr(HiVal, Context);
// Convert the value to the same width/sign as the condition.
ConvertIntegerToTypeWarnOnOverflow(HiVal, CondWidth, CondIsSigned,
CR->getRHS()->getLocStart(),
diag::warn_case_value_overflow);
+ // If the LHS is not the same type as the condition, insert an implicit
+ // cast.
+ ImpCastExprToType(Hi, CondType);
+ CR->setRHS(Hi);
+
// 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,
OpenPOWER on IntegriCloud