From db9edaf0539c4cc1e41e94c882ee7dbbb6d92b5b Mon Sep 17 00:00:00 2001 From: sgraf812 Date: Sat, 26 Jan 2013 01:50:04 +0100 Subject: [PATCH] Fix #265: Use declared struct type in initexpr. --- gen/llvmhelpers.cpp | 5 ++++- gen/toir.cpp | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index 673c5ad0..713d2482 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -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()) { diff --git a/gen/toir.cpp b/gen/toir.cpp index 387ea862..6e5bd2d2 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -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));