Mercurial > projects > ldc
diff gen/llvmhelpers.cpp @ 355:d8357f7004ca trunk
[svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
It is now possible to add label scopes in IrFunction and all labels names will be prefixed accordingly.
Also disallow goto into finally blocks.
Fixes nocompile/finally_02 and others.
author | ChristianK |
---|---|
date | Mon, 14 Jul 2008 11:48:55 +0200 |
parents | a7a26f538d6e |
children | 44daf304421c |
line wrap: on
line diff
--- a/gen/llvmhelpers.cpp Mon Jul 14 11:47:03 2008 +0200 +++ b/gen/llvmhelpers.cpp Mon Jul 14 11:48:55 2008 +0200 @@ -184,10 +184,10 @@ // if the target label is inside inline asm, error if(lblstmt->asmLabel) - error("cannot goto into inline asm block", loc->toChars()); + error(*loc, "cannot goto into inline asm block"); // find target basic block - std::string labelname = target->toChars(); + std::string labelname = gIR->func()->getScopedLabelName(target->toChars()); llvm::BasicBlock*& targetBB = gIR->func()->labelToBB[labelname]; if (targetBB == NULL) targetBB = llvm::BasicBlock::Create("label", gIR->topfunc()); @@ -200,7 +200,12 @@ // error if didn't find tf statement of label if(endfinally != lblstmt->enclosinghandler) - error("cannot goto into try block", loc->toChars()); + error(*loc, "cannot goto into try block"); + + // goto into finally blocks is forbidden by the spec + // though it should not be problematic to implement + if(lblstmt->tf) + error(*loc, "spec disallows goto into finally block"); // emit code for finallys between goto and label DtoEnclosingHandlers(enclosinghandler, endfinally); @@ -263,12 +268,20 @@ } assert(endfinally == end); + + // // emit code for finallys between start and end + // + + // since the labelstatements possibly inside are private + // and might already exist push a label scope + gIR->func()->pushUniqueLabelScope("enclosing"); EnclosingHandler* tf = start; while(tf != end) { tf->emitCode(gIR); tf = tf->getEnclosing(); } + gIR->func()->popLabelScope(); } /****************************************************************************************/