# HG changeset patch # User lindquist # Date 1213416815 -7200 # Node ID 2be09ee06bc7b1db9823073687089c9471db2c6f # Parent 88252a1af660d7959b22a50cbfa2d762f555e864 [svn r284] Fixed some problems with cases, code is not as pretty, but it doesn't crash llvm! diff -r 88252a1af660 -r 2be09ee06bc7 gen/statements.cpp --- a/gen/statements.cpp Sat Jun 14 05:13:49 2008 +0200 +++ b/gen/statements.cpp Sat Jun 14 06:13:35 2008 +0200 @@ -651,6 +651,14 @@ llvm::BasicBlock* oldend = gIR->scopeend(); + // clear data from previous passes... :/ + for (int i=0; idim; ++i) + { + CaseStatement* cs = (CaseStatement*)cases->data[i]; + cs->bodyBB = NULL; + cs->llvmIdx = NULL; + } + // string switch? llvm::GlobalVariable* switchTable = 0; Array caseArray; @@ -752,17 +760,15 @@ Logger::println("CaseStatement::toIR(): %s", loc.toChars()); LOG_SCOPE; - if (!bodyBB) + llvm::BasicBlock* nbb = llvm::BasicBlock::Create("case", p->topfunc(), p->scopeend()); + + if (bodyBB && !bodyBB->getTerminator()) { - bodyBB = llvm::BasicBlock::Create("case", p->topfunc(), p->scopeend()); + llvm::BranchInst::Create(nbb, bodyBB); } - else - { - bodyBB->moveAfter(p->scopebb()); - } + bodyBB = nbb; if (exp->type->isintegral()) { - assert(!llvmIdx); LLConstant* c = exp->toConstElem(p); llvmIdx = isaConstantInt(c); } @@ -787,7 +793,13 @@ assert(bodyBB); - bodyBB->moveAfter(p->scopebb()); + llvm::BasicBlock* nbb = llvm::BasicBlock::Create("default", p->topfunc(), p->scopeend()); + + if (!bodyBB->getTerminator()) + { + llvm::BranchInst::Create(nbb, bodyBB); + } + bodyBB = nbb; if (!p->scopereturned()) llvm::BranchInst::Create(bodyBB, p->scopebb()); @@ -1088,7 +1100,7 @@ assert(!p->scopereturned()); if (!cs->bodyBB) { - cs->bodyBB = llvm::BasicBlock::Create("case", p->topfunc(), p->scopeend()); + cs->bodyBB = llvm::BasicBlock::Create("goto_case", p->topfunc(), p->scopeend()); } emit_finallyblocks(p, enclosingtryfinally, sw->enclosingtryfinally);