mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-08-02 04:20:05 +02:00
DMD Issue 796 - Asserting a null object reference throws AssertError Failure internal\invariant.d(14) or Access Violation
This commit is contained in:
41
gen/toir.cpp
41
gen/toir.cpp
@@ -2104,8 +2104,26 @@ DValue* AssertExp::toElem(IRState* p)
|
|||||||
condty = e1->type->toBasetype();
|
condty = e1->type->toBasetype();
|
||||||
}
|
}
|
||||||
|
|
||||||
InvariantDeclaration* invdecl;
|
// create basic blocks
|
||||||
|
llvm::BasicBlock* oldend = p->scopeend();
|
||||||
|
llvm::BasicBlock* assertbb = llvm::BasicBlock::Create(gIR->context(), "assert", p->topfunc(), oldend);
|
||||||
|
llvm::BasicBlock* endbb = llvm::BasicBlock::Create(gIR->context(), "noassert", p->topfunc(), oldend);
|
||||||
|
|
||||||
|
// test condition
|
||||||
|
LLValue* condval = DtoCast(loc, cond, Type::tbool)->getRVal();
|
||||||
|
|
||||||
|
// branch
|
||||||
|
llvm::BranchInst::Create(endbb, assertbb, condval, p->scopebb());
|
||||||
|
|
||||||
|
// call assert runtime functions
|
||||||
|
p->scope() = IRScope(assertbb,endbb);
|
||||||
|
DtoAssert(p->func()->decl->getModule(), loc, msg ? msg->toElem(p) : NULL);
|
||||||
|
|
||||||
|
// rewrite the scope
|
||||||
|
p->scope() = IRScope(endbb,oldend);
|
||||||
|
|
||||||
|
|
||||||
|
InvariantDeclaration* invdecl;
|
||||||
// class invariants
|
// class invariants
|
||||||
if(
|
if(
|
||||||
global.params.useInvariants &&
|
global.params.useInvariants &&
|
||||||
@@ -2128,30 +2146,9 @@ DValue* AssertExp::toElem(IRState* p)
|
|||||||
DFuncValue invfunc(invdecl, invdecl->ir.irFunc->func, cond->getRVal());
|
DFuncValue invfunc(invdecl, invdecl->ir.irFunc->func, cond->getRVal());
|
||||||
DtoCallFunction(loc, NULL, &invfunc, NULL);
|
DtoCallFunction(loc, NULL, &invfunc, NULL);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// create basic blocks
|
|
||||||
llvm::BasicBlock* oldend = p->scopeend();
|
|
||||||
llvm::BasicBlock* assertbb = llvm::BasicBlock::Create(gIR->context(), "assert", p->topfunc(), oldend);
|
|
||||||
llvm::BasicBlock* endbb = llvm::BasicBlock::Create(gIR->context(), "noassert", p->topfunc(), oldend);
|
|
||||||
|
|
||||||
// test condition
|
|
||||||
LLValue* condval = DtoCast(loc, cond, Type::tbool)->getRVal();
|
|
||||||
|
|
||||||
// branch
|
|
||||||
llvm::BranchInst::Create(endbb, assertbb, condval, p->scopebb());
|
|
||||||
|
|
||||||
// call assert runtime functions
|
|
||||||
p->scope() = IRScope(assertbb,endbb);
|
|
||||||
DtoAssert(p->func()->decl->getModule(), loc, msg ? msg->toElem(p) : NULL);
|
|
||||||
|
|
||||||
// rewrite the scope
|
|
||||||
p->scope() = IRScope(endbb,oldend);
|
|
||||||
}
|
|
||||||
|
|
||||||
// DMD allows syntax like this:
|
// DMD allows syntax like this:
|
||||||
// f() == 0 || assert(false)
|
// f() == 0 || assert(false)
|
||||||
// TODO: or should we return true?
|
|
||||||
return new DImValue(type, DtoConstBool(false));
|
return new DImValue(type, DtoConstBool(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user