Fix #265: Use declared struct type in initexpr.

This commit is contained in:
sgraf812
2013-01-26 01:50:04 +01:00
committed by David Nadlinger
parent c77a6341af
commit db9edaf053
2 changed files with 10 additions and 2 deletions

View File

@@ -1396,7 +1396,10 @@ LLConstant* DtoConstInitializer(Loc loc, Type* type, Initializer* init)
if (!init)
{
Logger::println("const default initializer for %s", type->toChars());
_init = DtoConstExpInit(loc, type, type->defaultInit());
Expression *initExp = type->defaultInit();
if (type->ty == Ttypedef)
initExp->type = type; // This carries the typedef type into toConstElem.
_init = DtoConstExpInit(loc, type, initExp);
}
else if (ExpInitializer* ex = init->isExpInitializer())
{

View File

@@ -3068,7 +3068,12 @@ LLConstant* StructLiteralExp::toConstElem(IRState* p)
// return constant struct
if (!constType)
constType = LLStructType::get(gIR->context(), types);
{
if (type->ty == Ttypedef) // hack, see DtoConstInitializer.
constType = LLStructType::get(gIR->context(), types);
else
constType = isaStruct(DtoType(type));
}
else if (constType->isOpaque())
constType->setBody(types);
return LLConstantStruct::get(constType, llvm::makeArrayRef(constvals));