Changeset 1412:3f5ea912149d
- Timestamp:
- 05/22/09 18:23:39
(3 years ago)
- Author:
- Christian Kamm <kamm incasoftware de>
- branch:
- default
- Message:
Fix #308 by giving finally code emitted by EnclosingTryFinally? a different landing pad.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r1300 |
r1412 |
|
| 176 | 176 | llvm::CallSite IRState::CreateCallOrInvoke(LLValue* Callee, InputIterator ArgBegin, InputIterator ArgEnd, const char* Name) |
|---|
| 177 | 177 | { |
|---|
| 178 | | llvm::BasicBlock* pad; |
|---|
| 179 | | if(pad = func()->landingPad.get()) |
|---|
| | 178 | llvm::BasicBlock* pad = func()->landingPad; |
|---|
| | 179 | if(pad) |
|---|
| 180 | 180 | { |
|---|
| 181 | 181 | // intrinsics don't support invoking and 'nounwind' functions don't need it. |
|---|
| r1411 |
r1412 |
|
| 256 | 256 | { |
|---|
| 257 | 257 | if (tf->finalbody) |
|---|
| | 258 | { |
|---|
| | 259 | llvm::BasicBlock* oldpad = p->func()->landingPad; |
|---|
| | 260 | p->func()->landingPad = landingPad; |
|---|
| 258 | 261 | tf->finalbody->toIR(p); |
|---|
| | 262 | p->func()->landingPad = oldpad; |
|---|
| | 263 | } |
|---|
| 259 | 264 | } |
|---|
| 260 | 265 | |
|---|
| r1351 |
r1412 |
|
| 16 | 16 | { |
|---|
| 17 | 17 | TryFinallyStatement* tf; |
|---|
| | 18 | llvm::BasicBlock* landingPad; |
|---|
| 18 | 19 | void emitCode(IRState* p); |
|---|
| 19 | | EnclosingTryFinally(TryFinallyStatement* _tf) : tf(_tf) {} |
|---|
| | 20 | EnclosingTryFinally(TryFinallyStatement* _tf, llvm::BasicBlock* _pad) |
|---|
| | 21 | : tf(_tf), landingPad(_pad) {} |
|---|
| 20 | 22 | }; |
|---|
| 21 | 23 | struct EnclosingVolatile : EnclosingHandler |
|---|
| r1350 |
r1412 |
|
| 593 | 593 | |
|---|
| 594 | 594 | assert(finalbody); |
|---|
| 595 | | gIR->func()->landingPad.addFinally(finalbody); |
|---|
| 596 | | gIR->func()->landingPad.push(landingpadbb); |
|---|
| | 595 | gIR->func()->targetScopes.push_back(IRTargetScope(this,new EnclosingTryFinally(this,gIR->func()->landingPad),NULL,NULL)); |
|---|
| | 596 | gIR->func()->landingPadInfo.addFinally(finalbody); |
|---|
| | 597 | gIR->func()->landingPadInfo.push(landingpadbb); |
|---|
| | 598 | gIR->func()->landingPad = gIR->func()->landingPadInfo.get(); |
|---|
| 597 | 599 | |
|---|
| 598 | 600 | // |
|---|
| … | … | |
| 602 | 604 | |
|---|
| 603 | 605 | assert(body); |
|---|
| 604 | | p->func()->targetScopes.push_back(IRTargetScope(this,new EnclosingTryFinally(this),NULL,NULL)); |
|---|
| 605 | 606 | body->toIR(p); |
|---|
| 606 | | p->func()->targetScopes.pop_back(); |
|---|
| 607 | 607 | |
|---|
| 608 | 608 | // terminate try BB |
|---|
| … | … | |
| 610 | 610 | llvm::BranchInst::Create(finallybb, p->scopebb()); |
|---|
| 611 | 611 | |
|---|
| 612 | | gIR->func()->landingPad.pop(); |
|---|
| | 612 | gIR->func()->landingPadInfo.pop(); |
|---|
| | 613 | gIR->func()->landingPad = gIR->func()->landingPadInfo.get(); |
|---|
| | 614 | gIR->func()->targetScopes.pop_back(); |
|---|
| 613 | 615 | |
|---|
| 614 | 616 | // |
|---|
| … | … | |
| 659 | 661 | { |
|---|
| 660 | 662 | Catch *c = (Catch *)catches->data[i]; |
|---|
| 661 | | gIR->func()->landingPad.addCatch(c, endbb); |
|---|
| 662 | | } |
|---|
| 663 | | |
|---|
| 664 | | gIR->func()->landingPad.push(landingpadbb); |
|---|
| | 663 | gIR->func()->landingPadInfo.addCatch(c, endbb); |
|---|
| | 664 | } |
|---|
| | 665 | |
|---|
| | 666 | gIR->func()->landingPadInfo.push(landingpadbb); |
|---|
| | 667 | gIR->func()->landingPad = gIR->func()->landingPadInfo.get(); |
|---|
| 665 | 668 | |
|---|
| 666 | 669 | // |
|---|
| … | … | |
| 675 | 678 | llvm::BranchInst::Create(endbb, p->scopebb()); |
|---|
| 676 | 679 | |
|---|
| 677 | | gIR->func()->landingPad.pop(); |
|---|
| | 680 | gIR->func()->landingPadInfo.pop(); |
|---|
| | 681 | gIR->func()->landingPad = gIR->func()->landingPadInfo.get(); |
|---|
| 678 | 682 | |
|---|
| 679 | 683 | // rewrite the scope |
|---|
| r1223 |
r1412 |
|
| 118 | 118 | _argptr = NULL; |
|---|
| 119 | 119 | |
|---|
| | 120 | landingPad = NULL; |
|---|
| | 121 | |
|---|
| 120 | 122 | nextUnique.push(0); |
|---|
| 121 | 123 | } |
|---|
| r1223 |
r1412 |
|
| 71 | 71 | |
|---|
| 72 | 72 | // landing pads for try statements |
|---|
| 73 | | IRLandingPad landingPad; |
|---|
| | 73 | IRLandingPad landingPadInfo; |
|---|
| | 74 | llvm::BasicBlock* landingPad; |
|---|
| 74 | 75 | |
|---|
| 75 | 76 | // loop blocks |
|---|
| r1350 |
r1412 |
|
| 25 | 25 | assert(!catchstmt->var->ir.irLocal); |
|---|
| 26 | 26 | catchstmt->var->ir.irLocal = new IrLocal(catchstmt->var); |
|---|
| 27 | | LLValue* catch_var = gIR->func()->landingPad.getExceptionStorage(); |
|---|
| | 27 | LLValue* catch_var = gIR->func()->landingPadInfo.getExceptionStorage(); |
|---|
| 28 | 28 | catchstmt->var->ir.irLocal->value = gIR->ir->CreateBitCast(catch_var, getPtrToType(DtoType(catchstmt->var->type))); |
|---|
| 29 | 29 | } |
|---|
| … | … | |
| 33 | 33 | |
|---|
| 34 | 34 | // the exception will only be stored in catch_var. copy it over if necessary |
|---|
| 35 | | if(catchstmt->var->ir.irLocal->value != gIR->func()->landingPad.getExceptionStorage()) { |
|---|
| 36 | | LLValue* exc = gIR->ir->CreateBitCast(DtoLoad(gIR->func()->landingPad.getExceptionStorage()), DtoType(catchstmt->var->type)); |
|---|
| | 35 | if(catchstmt->var->ir.irLocal->value != gIR->func()->landingPadInfo.getExceptionStorage()) { |
|---|
| | 36 | LLValue* exc = gIR->ir->CreateBitCast(DtoLoad(gIR->func()->landingPadInfo.getExceptionStorage()), DtoType(catchstmt->var->type)); |
|---|
| 37 | 37 | DtoStore(exc, catchstmt->var->ir.irLocal->value); |
|---|
| 38 | 38 | } |
|---|