mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-04 17:11:44 +03:00
Changed aggregate field initializers to be created lazily, fixes problem with static void arrays in aggregates.
This commit is contained in:
parent
f46f865375
commit
13e0399ab0
3 changed files with 11 additions and 29 deletions
|
@ -427,21 +427,6 @@ void addZeros(std::vector<llvm::Constant*>& inits, size_t pos, size_t offset); /
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// assigns constant initializers to fields introduced by cd
|
|
||||||
static void init_field_inits(ClassDeclaration* cd)
|
|
||||||
{
|
|
||||||
size_t n = cd->fields.dim;
|
|
||||||
for (size_t i=0; i<n; i++)
|
|
||||||
{
|
|
||||||
VarDeclaration* v = (VarDeclaration*)cd->fields.data[i];
|
|
||||||
IrField* f = v->ir.irField;
|
|
||||||
assert(!f->constInit);
|
|
||||||
f->constInit = DtoConstFieldInitializer(v->loc, v->type, v->init);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
// adds data fields and interface vtables to the constant initializer of class cd
|
// adds data fields and interface vtables to the constant initializer of class cd
|
||||||
static size_t init_class_initializer(std::vector<LLConstant*>& inits, ClassDeclaration* target, ClassDeclaration* cd, size_t offsetbegin)
|
static size_t init_class_initializer(std::vector<LLConstant*>& inits, ClassDeclaration* target, ClassDeclaration* cd, size_t offsetbegin)
|
||||||
{
|
{
|
||||||
|
@ -502,7 +487,9 @@ static size_t init_class_initializer(std::vector<LLConstant*>& inits, ClassDecla
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the field
|
// add the field
|
||||||
assert(var->ir.irField->constInit);
|
// and build its constant initializer lazily
|
||||||
|
if (!var->ir.irField->constInit)
|
||||||
|
var->ir.irField->constInit = DtoConstFieldInitializer(var->loc, var->type, var->init);
|
||||||
inits.push_back(var->ir.irField->constInit);
|
inits.push_back(var->ir.irField->constInit);
|
||||||
|
|
||||||
lastoffset = offset;
|
lastoffset = offset;
|
||||||
|
@ -731,9 +718,6 @@ void DtoConstInitClass(ClassDeclaration* cd)
|
||||||
const llvm::ArrayType* vtbltype = isaArray(irstruct->vtblTy.get());
|
const llvm::ArrayType* vtbltype = isaArray(irstruct->vtblTy.get());
|
||||||
assert(vtbltype);
|
assert(vtbltype);
|
||||||
|
|
||||||
// make sure each field knows its default initializer
|
|
||||||
init_field_inits(cd);
|
|
||||||
|
|
||||||
// build initializer list
|
// build initializer list
|
||||||
std::vector<LLConstant*> inits;
|
std::vector<LLConstant*> inits;
|
||||||
inits.reserve(irstruct->varDecls.size());
|
inits.reserve(irstruct->varDecls.size());
|
||||||
|
|
|
@ -208,6 +208,8 @@ Lpadding:
|
||||||
|
|
||||||
// do the default
|
// do the default
|
||||||
Logger::println("adding default field: %s : +%u", nextdef->toChars(), nextdef->offset);
|
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);
|
||||||
LLConstant* c = nextdef->ir.irField->constInit;
|
LLConstant* c = nextdef->ir.irField->constInit;
|
||||||
inits.push_back(c);
|
inits.push_back(c);
|
||||||
|
|
||||||
|
@ -261,6 +263,8 @@ Lpadding2:
|
||||||
|
|
||||||
// do the default
|
// do the default
|
||||||
Logger::println("adding default field: %s : +%u", nextdef->toChars(), nextdef->offset);
|
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);
|
||||||
LLConstant* c = nextdef->ir.irField->constInit;
|
LLConstant* c = nextdef->ir.irField->constInit;
|
||||||
inits.push_back(c);
|
inits.push_back(c);
|
||||||
|
|
||||||
|
@ -463,15 +467,6 @@ void DtoConstInitStruct(StructDeclaration* sd)
|
||||||
|
|
||||||
const llvm::StructType* structtype = isaStruct(sd->type->ir.type->get());
|
const llvm::StructType* structtype = isaStruct(sd->type->ir.type->get());
|
||||||
|
|
||||||
// make sure each offset knows its default initializer
|
|
||||||
Array* fields = &sd->fields;
|
|
||||||
for (int k=0; k < fields->dim; k++)
|
|
||||||
{
|
|
||||||
VarDeclaration* v = (VarDeclaration*)fields->data[k];
|
|
||||||
LLConstant* finit = DtoConstFieldInitializer(v->loc, v->type, v->init);
|
|
||||||
v->ir.irField->constInit = finit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// always generate the constant initalizer
|
// always generate the constant initalizer
|
||||||
if (sd->zeroInit)
|
if (sd->zeroInit)
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "gen/irstate.h"
|
#include "gen/irstate.h"
|
||||||
#include "gen/tollvm.h"
|
#include "gen/tollvm.h"
|
||||||
#include "gen/logger.h"
|
#include "gen/logger.h"
|
||||||
|
#include "gen/llvmhelpers.h"
|
||||||
|
|
||||||
IrInterface::IrInterface(BaseClass* b)
|
IrInterface::IrInterface(BaseClass* b)
|
||||||
: vtblInitTy(llvm::OpaqueType::get())
|
: vtblInitTy(llvm::OpaqueType::get())
|
||||||
|
@ -318,7 +319,9 @@ void IrStruct::buildDefaultConstInit(std::vector<llvm::Constant*>& inits)
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the field
|
// add the field
|
||||||
assert(var->ir.irField->constInit);
|
// lazily default initialize
|
||||||
|
if (!var->ir.irField->constInit)
|
||||||
|
var->ir.irField->constInit = DtoConstFieldInitializer(var->loc, var->type, var->init);
|
||||||
inits.push_back(var->ir.irField->constInit);
|
inits.push_back(var->ir.irField->constInit);
|
||||||
|
|
||||||
lastoffset = offset;
|
lastoffset = offset;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue