mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-02 08:01:11 +03:00
Handle new throw expressions
This commit is contained in:
parent
78681e12e1
commit
5c9f1e5fd6
4 changed files with 32 additions and 14 deletions
|
@ -270,7 +270,7 @@ LLValue *DtoAllocaDump(LLValue *val, LLType *asType, int alignment,
|
|||
}
|
||||
|
||||
/******************************************************************************
|
||||
* ASSERT HELPER
|
||||
* ASSERT HELPERS
|
||||
******************************************************************************/
|
||||
|
||||
void DtoAssert(Module *M, const Loc &loc, DValue *msg) {
|
||||
|
@ -339,6 +339,21 @@ void DtoCAssert(Module *M, const Loc &loc, LLValue *msg) {
|
|||
gIR->ir->CreateUnreachable();
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* THROW HELPER
|
||||
******************************************************************************/
|
||||
|
||||
void DtoThrow(const Loc &loc, DValue *e) {
|
||||
LLFunction *fn = getRuntimeFunction(loc, gIR->module, "_d_throw_exception");
|
||||
LLValue *arg = DtoBitCast(DtoRVal(e), fn->getFunctionType()->getParamType(0));
|
||||
|
||||
gIR->CreateCallOrInvoke(fn, arg);
|
||||
gIR->ir->CreateUnreachable();
|
||||
|
||||
llvm::BasicBlock *bb = gIR->insertBB("afterthrow");
|
||||
gIR->ir->SetInsertPoint(bb);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* MODULE FILE NAME
|
||||
******************************************************************************/
|
||||
|
|
|
@ -63,6 +63,8 @@ LLValue *DtoAllocaDump(LLValue *val, LLType *asType, int alignment = 0,
|
|||
void DtoAssert(Module *M, const Loc &loc, DValue *msg);
|
||||
void DtoCAssert(Module *M, const Loc &loc, LLValue *msg);
|
||||
|
||||
void DtoThrow(const Loc &loc, DValue *e);
|
||||
|
||||
// returns module file name
|
||||
LLConstant *DtoModuleFileName(Module *M, const Loc &loc);
|
||||
|
||||
|
|
|
@ -934,19 +934,7 @@ public:
|
|||
emitCoverageLinecountInc(stmt->loc);
|
||||
|
||||
assert(stmt->exp);
|
||||
DValue *e = toElemDtor(stmt->exp);
|
||||
|
||||
llvm::Function *fn =
|
||||
getRuntimeFunction(stmt->loc, irs->module, "_d_throw_exception");
|
||||
LLValue *arg =
|
||||
DtoBitCast(DtoRVal(e), fn->getFunctionType()->getParamType(0));
|
||||
|
||||
irs->CreateCallOrInvoke(fn, arg);
|
||||
irs->ir->CreateUnreachable();
|
||||
|
||||
// TODO: Should not be needed.
|
||||
llvm::BasicBlock *bb = irs->insertBB("afterthrow");
|
||||
irs->ir->SetInsertPoint(bb);
|
||||
DtoThrow(stmt->loc, toElemDtor(stmt->exp));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
|
13
gen/toir.cpp
13
gen/toir.cpp
|
@ -1587,6 +1587,19 @@ public:
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void visit(ThrowExp *e) override {
|
||||
IF_LOG Logger::print("ThrowExp::toElem: %s\n", e->toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
auto &PGO = gIR->funcGen().pgo;
|
||||
PGO.setCurrentStmt(e);
|
||||
|
||||
DtoThrow(e->loc, toElem(e->e1));
|
||||
result = new DNullValue(e->type, llvm::UndefValue::get(DtoType(e->type)));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void visit(AssertExp *e) override {
|
||||
IF_LOG Logger::print("AssertExp::toElem: %s\n", e->toChars());
|
||||
LOG_SCOPE;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue