aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CodeGen/CGStmt.cpp4
-rw-r--r--test/CodeGen/switch.c2
2 files changed, 5 insertions, 1 deletions
diff --git a/CodeGen/CGStmt.cpp b/CodeGen/CGStmt.cpp
index 6a2e3aa543..9665e7dc63 100644
--- a/CodeGen/CGStmt.cpp
+++ b/CodeGen/CGStmt.cpp
@@ -444,7 +444,9 @@ void CodeGenFunction::EmitCaseStmt(const CaseStmt &S) {
StartBlock("sw.bb");
llvm::BasicBlock *CaseDest = Builder.GetInsertBlock();
- llvm::ConstantInt *LV = cast<llvm::ConstantInt>(EmitScalarExpr(S.getLHS()));
+ llvm::APSInt CaseVal(32);
+ S.getLHS()->isIntegerConstantExpr(CaseVal, getContext());
+ llvm::ConstantInt *LV = llvm::ConstantInt::get(CaseVal);
SwitchInsn->addCase(LV, CaseDest);
EmitStmt(S.getSubStmt());
}
diff --git a/test/CodeGen/switch.c b/test/CodeGen/switch.c
index 68313c0741..a4d77b9c19 100644
--- a/test/CodeGen/switch.c
+++ b/test/CodeGen/switch.c
@@ -3,6 +3,8 @@
int foo(int i) {
int j = 0;
switch (i) {
+ case -1:
+ j = 1; break;
case 1 :
j = 2; break;
case 2: