Fixed struct default initializers.

This commit is contained in:
Tomas Lindquist Olsen
2009-04-25 18:26:54 +02:00
parent d21cdb1df0
commit 3e882d422b
6 changed files with 163 additions and 45 deletions

View File

@@ -142,6 +142,9 @@ LLConstant * IrStruct::createStructDefaultInitializer()
assert(type->ty == Tstruct && "cannot build struct default initializer for non struct type");
IrTypeStruct* ts = type->irtype->isStruct();
assert(ts);
// start at offset zero
size_t offset = 0;
@@ -149,10 +152,10 @@ LLConstant * IrStruct::createStructDefaultInitializer()
std::vector<llvm::Constant*> constants;
// go through fields
ArrayIter<VarDeclaration> it(aggrdecl->fields);
for (; !it.done(); it.next())
IrTypeAggr::iterator it;
for (it = ts->def_begin(); it != ts->def_end(); ++it)
{
VarDeclaration* vd = it.get();
VarDeclaration* vd = *it;
if (vd->offset < offset)
{
@@ -195,12 +198,6 @@ LLConstant * IrStruct::createStructDefaultInitializer()
IF_LOG Logger::cout() << "final default initializer: " << *definit << std::endl;
#endif
// sanity check
if (definit->getType() != type->irtype->get())
{
assert(0 && "default initializer type does not match the default struct type");
}
return definit;
}