Fixed a nasty bug with how interface vtables for class initializers were output, causing some class fields to be skipped.

Fixed a problem in definition of ClassInfos where an invalid constant was potentially used. This needs to be looked into proper as it might happen again in the future.
This commit is contained in:
Tomas Lindquist Olsen 2008-12-01 04:37:54 +01:00
parent e0972b0793
commit 8ee1fbca26
3 changed files with 8 additions and 6 deletions

View file

@ -435,7 +435,7 @@ static size_t init_class_initializer(std::vector<LLConstant*>& inits, ClassDecla
offsetbegin = init_class_initializer(inits, target, cd->baseClass, offsetbegin);
}
Logger::println("adding data of %s to %s", cd->toChars(), target->toChars());
Logger::println("adding data of %s to %s starting at %lu", cd->toChars(), target->toChars(), offsetbegin);
LOG_SCOPE;
// add default fields
@ -464,7 +464,7 @@ static size_t init_class_initializer(std::vector<LLConstant*>& inits, ClassDecla
}
else
{
Logger::println(" skipped %s", var->toChars());
Logger::println(" skipped %s at offset %u, current pos is %lu", var->toChars(), var->offset, lastoffset+lastsize);
}
}
@ -519,7 +519,7 @@ static size_t init_class_initializer(std::vector<LLConstant*>& inits, ClassDecla
else // abstract impl
inits.push_back(getNullPtr(getVoidPtrType()));
lastoffset += PTRSIZE;
lastoffset += lastsize;
lastsize = PTRSIZE;
}
@ -749,6 +749,7 @@ void DtoConstInitClass(ClassDeclaration* cd)
init_class_interface_vtbl_initializers(cd);
// build constant from inits
assert(!irstruct->constInit);
irstruct->constInit = LLConstantStruct::get(inits); // classes are never packed
// refine __initZ global type to the one of the initializer
@ -1437,7 +1438,7 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
assert(ir->classInfo);
TypeClass* cdty = (TypeClass*)cd->type;
if (!cd->isInterfaceDeclaration() && !cd->isAbstract())
if (!cd->isInterfaceDeclaration())
{
assert(ir->init);
assert(ir->constInit);
@ -1450,7 +1451,6 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
ClassDeclaration* cinfo = ClassDeclaration::classinfo;
DtoForceConstInitDsymbol(cinfo);
assert(cinfo->ir.irStruct->constInit);
LLConstant* c;
@ -1473,7 +1473,7 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
{
c = DtoBitCast(ir->init, voidPtr);
//Logger::cout() << *ir->constInit->getType() << std::endl;
size_t initsz = getABITypeSize(ir->constInit->getType());
size_t initsz = getABITypeSize(ir->init->getType()->getContainedType(0));
c = DtoConstSlice(DtoConstSize_t(initsz), c);
}
inits.push_back(c);

View file

@ -1005,6 +1005,7 @@ void DtoConstInitGlobal(VarDeclaration* vd)
// refine the global's opaque type to the type of the initializer
llvm::cast<LLOpaqueType>(glob->type.get())->refineAbstractTypeTo(initVal->getType());
assert(!glob->constInit);
glob->constInit = initVal;
bool istempl = false;

View file

@ -467,6 +467,7 @@ void DtoConstInitStruct(StructDeclaration* sd)
const llvm::StructType* structtype = isaStruct(sd->type->ir.type->get());
// always generate the constant initalizer
assert(!irstruct->constInit);
if (sd->zeroInit)
{
Logger::println("Zero initialized");