Skip to content
Browse files

when there are multiple returns in an ensure,

the function should now return the correct value

(this bug was found thanks to LLVM's module verifier)

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@2325 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent deb8c49 commit 5d7a33f530c4595bb8a3e4226f1f9449536a0514 @vincentisambart vincentisambart committed Aug 15, 2009
Showing with 12 additions and 2 deletions.
  1. +9 −0 compiler.cpp
  2. +1 −0 compiler.h
  3. +2 −2 vm.cpp
View
9 compiler.cpp
@@ -51,6 +51,7 @@ RoxorCompiler::RoxorCompiler(void)
current_rescue = false;
return_from_block = -1;
return_from_block_ids = 0;
+ ensure_pn = NULL;
dispatcherFunc = NULL;
fastPlusFunc = NULL;
@@ -1679,6 +1680,7 @@ RoxorCompiler::compile_jump(NODE *node)
else {
if (ensure_bb != NULL) {
BranchInst::Create(ensure_bb, bb);
+ ensure_pn->addIncoming(val, bb);
}
else {
ReturnInst::Create(val, bb);
@@ -4498,7 +4500,9 @@ RoxorCompiler::compile_node(NODE *node)
Function *f = bb->getParent();
BasicBlock *old_ensure_bb = ensure_bb;
+ PHINode *old_ensure_pn = ensure_pn;
ensure_bb = BasicBlock::Create("ensure", f);
+ ensure_pn = PHINode::Create(RubyObjTy, "ensure.phi", ensure_bb);
Value *val;
if (nd_type(node->nd_head) != NODE_RESCUE) {
@@ -4515,6 +4519,7 @@ RoxorCompiler::compile_node(NODE *node)
DEBUG_LEVEL_DEC();
rescue_bb = old_rescue_bb;
BranchInst::Create(ensure_bb, bb);
+ ensure_pn->addIncoming(val, bb);
bb = new_rescue_bb;
compile_landing_pad_header();
@@ -4524,10 +4529,14 @@ RoxorCompiler::compile_node(NODE *node)
else {
val = compile_node(node->nd_head);
BranchInst::Create(ensure_bb, bb);
+ ensure_pn->addIncoming(val, bb);
}
+ val = ensure_pn;
+
bb = ensure_bb;
ensure_bb = old_ensure_bb;
+ ensure_pn = old_ensure_pn;
compile_node(node->nd_ensr);
return val;
View
1 compiler.h
@@ -102,6 +102,7 @@ class RoxorCompiler {
Value *current_loop_exit_val;
int return_from_block;
int return_from_block_ids;
+ PHINode *ensure_pn;
Function *dispatcherFunc;
Function *fastPlusFunc;
View
4 vm.cpp
@@ -361,7 +361,7 @@ RoxorCore::compile(Function *func)
}
#if ROXOR_COMPILER_DEBUG
- if (verifyModule(*RoxorCompiler::module)) {
+ if (verifyModule(*RoxorCompiler::module, PrintMessageAction)) {
printf("Error during module verification\n");
exit(1);
}
@@ -385,7 +385,7 @@ RoxorCore::compile(Function *func)
uint64_t elapsedNano = elapsed * sTimebaseInfo.numer / sTimebaseInfo.denom;
- printf("compilation of LLVM function %p done, took %lld ns\n",
+ fprintf(stderr, "compilation of LLVM function %p done, took %lld ns\n",
func, elapsedNano);
#endif

0 comments on commit 5d7a33f

Please sign in to comment.
Something went wrong with that request. Please try again.