From ae48a1925125b3c1efa512b10637e85cb0e5621c Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sun, 2 Jun 2013 20:08:09 +0200 Subject: [PATCH] Refactoring-only part of DtoConstExpInit fix. --- gen/llvmhelpers.cpp | 37 ++++++++++++++++--------------------- gen/llvmhelpers.h | 2 +- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index bee487f101..b548960ddb 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -1308,18 +1308,11 @@ LLConstant* DtoConstInitializer(Loc loc, Type* type, Initializer* init) ////////////////////////////////////////////////////////////////////////////////////////// -static LLConstant* expand_to_sarray(Type *base, Expression* exp) +static LLConstant* expand_to_sarray(Type* targetType, Type* initType, LLConstant* initConst) { - Logger::println("building type %s from expression (%s) of type %s", base->toChars(), exp->toChars(), exp->type->toChars()); - LLType* dstTy = DtoType(base); - if (Logger::enabled()) - Logger::cout() << "final llvm type requested: " << *dstTy << '\n'; - - LLConstant* val = exp->toConstElem(gIR); - - Type* expbase = stripModifiers(exp->type->toBasetype()); - Logger::println("expbase: %s", expbase->toChars()); - Type* t = base->toBasetype(); + Type* expbase = stripModifiers(initType); + IF_LOG Logger::println("expbase: %s", expbase->toChars()); + Type* t = targetType; LLSmallVector dims; @@ -1341,19 +1334,21 @@ static LLConstant* expand_to_sarray(Type *base, Expression* exp) std::vector inits; while (i--) { - LLArrayType* arrty = LLArrayType::get(val->getType(), dims[i]); + LLArrayType* arrty = LLArrayType::get(initConst->getType(), dims[i]); inits.clear(); - inits.insert(inits.end(), dims[i], val); - val = LLConstantArray::get(arrty, inits); + inits.insert(inits.end(), dims[i], initConst); + initConst = LLConstantArray::get(arrty, inits); } - return val; + return initConst; } -LLConstant* DtoConstExpInit(Loc loc, Type* type, Expression* exp) +LLConstant* DtoConstExpInit(Loc loc, Type* targetType, Expression* exp) { + LLConstant* val = exp->toConstElem(gIR); + Type* expbase = stripModifiers(exp->type->toBasetype())->merge(); - Type* base = stripModifiers(type->toBasetype())->merge(); + Type* base = stripModifiers(targetType->toBasetype())->merge(); // if not the same basetypes, we won't get the same llvm types either if (!expbase->equals(base)) @@ -1365,12 +1360,12 @@ LLConstant* DtoConstExpInit(Loc loc, Type* type, Expression* exp) fatal(); } Logger::println("type is a static array, building constant array initializer to single value"); - return expand_to_sarray(base, exp); + return expand_to_sarray(base, expbase, val); } if (base->ty == Tvector) { - LLConstant* val = exp->toConstElem(gIR); + TypeVector* tv = (TypeVector*)base; assert(tv->basetype->ty == Tsarray); @@ -1386,11 +1381,11 @@ LLConstant* DtoConstExpInit(Loc loc, Type* type, Expression* exp) } error(loc, "LDC internal error: cannot yet convert default initializer %s of type %s to %s", - exp->toChars(), exp->type->toChars(), type->toChars()); + exp->toChars(), exp->type->toChars(), targetType->toChars()); llvm_unreachable("Unsupported default initializer."); } - return exp->toConstElem(gIR); + return val; } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/gen/llvmhelpers.h b/gen/llvmhelpers.h index 483e24c7d3..fc807b7d85 100644 --- a/gen/llvmhelpers.h +++ b/gen/llvmhelpers.h @@ -115,7 +115,7 @@ LLValue* DtoRawVarDeclaration(VarDeclaration* var, LLValue* addr = 0); // initializer helpers LLConstant* DtoConstInitializer(Loc loc, Type* type, Initializer* init); -LLConstant* DtoConstExpInit(Loc loc, Type* t, Expression* exp); +LLConstant* DtoConstExpInit(Loc loc, Type* targetType, Expression* exp); // getting typeinfo of type, base=true casts to object.TypeInfo LLConstant* DtoTypeInfoOf(Type* ty, bool base=true);