mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-11 18:33:14 +01:00
Return null from a static class to interface cast if the class reference was
null. Fixes #237.
This commit is contained in:
@@ -1067,13 +1067,21 @@ DValue* DtoCastClass(DValue* val, Type* _to)
|
||||
IrInterface* iri = iriter->second;
|
||||
// offset pointer
|
||||
LLValue* v = val->getRVal();
|
||||
LLValue* orig = v;
|
||||
v = DtoGEPi(v, 0, iri->index);
|
||||
const LLType* ifType = DtoType(_to);
|
||||
if (Logger::enabled())
|
||||
{
|
||||
Logger::cout() << "V = " << *v << std::endl;
|
||||
Logger::cout() << "T = " << *DtoType(_to) << std::endl;
|
||||
Logger::cout() << "T = " << *ifType << std::endl;
|
||||
}
|
||||
v = DtoBitCast(v, DtoType(_to));
|
||||
v = DtoBitCast(v, ifType);
|
||||
// Check whether the original value was null, and return null if so.
|
||||
// Sure we could have jumped over the code above in this case, but
|
||||
// it's just a GEP and (maybe) a pointer-to-pointer BitCast, so it
|
||||
// should be pretty cheap and perfectly safe even if the original was null.
|
||||
LLValue* isNull = gIR->ir->CreateICmpEQ(orig, LLConstant::getNullValue(orig->getType()), ".nullcheck");
|
||||
v = gIR->ir->CreateSelect(isNull, LLConstant::getNullValue(ifType), v, ".interface");
|
||||
// return r-value
|
||||
return new DImValue(_to, v);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user