From 5d1366d27f998c3bcda03f2c10bc1d020363f904 Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Sat, 29 Nov 2008 21:26:50 +0100 Subject: [PATCH] Removed DtoConstFieldInitializer, it's no longer needed and was buggy. --- gen/classes.cpp | 2 +- gen/llvmhelpers.cpp | 60 --------------------------------------------- gen/llvmhelpers.h | 1 - gen/structs.cpp | 4 +-- ir/irstruct.cpp | 2 +- 5 files changed, 4 insertions(+), 65 deletions(-) diff --git a/gen/classes.cpp b/gen/classes.cpp index a8debc3c..89803e17 100644 --- a/gen/classes.cpp +++ b/gen/classes.cpp @@ -485,7 +485,7 @@ static size_t init_class_initializer(std::vector& inits, ClassDecla // add the field // and build its constant initializer lazily if (!var->ir.irField->constInit) - var->ir.irField->constInit = DtoConstFieldInitializer(var->loc, var->type, var->init); + var->ir.irField->constInit = DtoConstInitializer(var->loc, var->type, var->init); inits.push_back(var->ir.irField->constInit); lastoffset = offset; diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index 7e1ece5d..4d707838 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -1428,55 +1428,6 @@ LLConstant* DtoConstInitializer(Loc loc, Type* type, Initializer* init) ////////////////////////////////////////////////////////////////////////////////////////// -LLConstant* DtoConstFieldInitializer(Loc loc, Type* t, Initializer* init) -{ - Logger::println("DtoConstFieldInitializer"); - LOG_SCOPE; - - const LLType* _type = DtoType(t); - - LLConstant* _init = DtoConstInitializer(loc, t, init); - assert(_init); - if (_type != _init->getType()) - { - if (Logger::enabled()) - Logger::cout() << "field init is: " << *_init << " type should be " << *_type << '\n'; - if (t->ty == Tsarray) - { - const LLArrayType* arrty = isaArray(_type); - uint64_t n = arrty->getNumElements(); - std::vector vals(n,_init); - _init = llvm::ConstantArray::get(arrty, vals); - } - else if (t->ty == Tarray) - { - assert(isaStruct(_type)); - _init = llvm::ConstantAggregateZero::get(_type); - } - else if (t->ty == Tstruct) - { - const LLStructType* structty = isaStruct(_type); - TypeStruct* ts = (TypeStruct*)t; - assert(ts); - assert(ts->sym); - assert(ts->sym->ir.irStruct->constInit); - _init = ts->sym->ir.irStruct->constInit; - } - else if (t->ty == Tclass) - { - _init = llvm::Constant::getNullValue(_type); - } - else { - Logger::println("failed for type %s", t->toChars()); - assert(0); - } - } - - return _init; -} - -////////////////////////////////////////////////////////////////////////////////////////// - DValue* DtoInitializer(LLValue* target, Initializer* init) { if (!init) @@ -1538,17 +1489,6 @@ static LLConstant* expand_to_sarray(Type *base, Expression* exp) LLSmallVector dims; - // handle zero initializers - if (expbase->isintegral() && exp->isConst()) - { - if (!exp->toInteger()) - return LLConstant::getNullValue(dstTy); - } - else if (exp->op == TOKnull) - { - return LLConstant::getNullValue(dstTy); - } - while(1) { Logger::println("t: %s", t->toChars()); diff --git a/gen/llvmhelpers.h b/gen/llvmhelpers.h index b52988a9..83e087ef 100644 --- a/gen/llvmhelpers.h +++ b/gen/llvmhelpers.h @@ -87,7 +87,6 @@ LLValue* DtoRawVarDeclaration(VarDeclaration* var); // initializer helpers LLConstant* DtoConstInitializer(Loc loc, Type* type, Initializer* init); -LLConstant* DtoConstFieldInitializer(Loc loc, Type* type, Initializer* init); LLConstant* DtoConstExpInit(Loc loc, Type* t, Expression* exp); DValue* DtoInitializer(LLValue* target, Initializer* init); diff --git a/gen/structs.cpp b/gen/structs.cpp index b6d836b9..fbe7ce83 100644 --- a/gen/structs.cpp +++ b/gen/structs.cpp @@ -208,7 +208,7 @@ Lpadding: // do the default Logger::println("adding default field: %s : +%u", nextdef->toChars(), nextdef->offset); if (!nextdef->ir.irField->constInit) - nextdef->ir.irField->constInit = DtoConstFieldInitializer(nextdef->loc, nextdef->type, nextdef->init); + nextdef->ir.irField->constInit = DtoConstInitializer(nextdef->loc, nextdef->type, nextdef->init); LLConstant* c = nextdef->ir.irField->constInit; inits.push_back(c); @@ -263,7 +263,7 @@ Lpadding2: // do the default Logger::println("adding default field: %s : +%u", nextdef->toChars(), nextdef->offset); if (!nextdef->ir.irField->constInit) - nextdef->ir.irField->constInit = DtoConstFieldInitializer(nextdef->loc, nextdef->type, nextdef->init); + nextdef->ir.irField->constInit = DtoConstInitializer(nextdef->loc, nextdef->type, nextdef->init); LLConstant* c = nextdef->ir.irField->constInit; inits.push_back(c); diff --git a/ir/irstruct.cpp b/ir/irstruct.cpp index b3b92b2a..e87ee190 100644 --- a/ir/irstruct.cpp +++ b/ir/irstruct.cpp @@ -319,7 +319,7 @@ void IrStruct::buildDefaultConstInit(std::vector& inits) // add the field // lazily default initialize if (!var->ir.irField->constInit) - var->ir.irField->constInit = DtoConstFieldInitializer(var->loc, var->type, var->init); + var->ir.irField->constInit = DtoConstInitializer(var->loc, var->type, var->init); inits.push_back(var->ir.irField->constInit); lastoffset = offset;