changeset 812:6c2ff06c4201

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.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Mon, 01 Dec 2008 04:37:54 +0100
parents 8e6135be6999
children 2eaefe4a550b
files gen/classes.cpp gen/llvmhelpers.cpp gen/structs.cpp
diffstat 3 files changed, 8 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/gen/classes.cpp	Mon Dec 01 02:10:16 2008 +0100
+++ b/gen/classes.cpp	Mon Dec 01 04:37:54 2008 +0100
@@ -435,7 +435,7 @@
         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 @@
         }
         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 @@
         else // abstract impl
             inits.push_back(getNullPtr(getVoidPtrType()));
 
-        lastoffset += PTRSIZE;
+        lastoffset += lastsize;
         lastsize = PTRSIZE;
     }
 
@@ -749,6 +749,7 @@
     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 @@
     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 @@
 
     ClassDeclaration* cinfo = ClassDeclaration::classinfo;
     DtoForceConstInitDsymbol(cinfo);
-    assert(cinfo->ir.irStruct->constInit);
 
     LLConstant* c;
 
@@ -1473,7 +1473,7 @@
     {
         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);
--- a/gen/llvmhelpers.cpp	Mon Dec 01 02:10:16 2008 +0100
+++ b/gen/llvmhelpers.cpp	Mon Dec 01 04:37:54 2008 +0100
@@ -1005,6 +1005,7 @@
     // 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;
--- a/gen/structs.cpp	Mon Dec 01 02:10:16 2008 +0100
+++ b/gen/structs.cpp	Mon Dec 01 04:37:54 2008 +0100
@@ -467,6 +467,7 @@
     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");