diff gen/toobj.c @ 23:77e3d1ddae3f trunk

[svn r27] * Fixed bug in aggregate field lookup. * Fixed structs with no fields. * Added support for NegExp as in -x.
author lindquist
date Thu, 04 Oct 2007 09:24:15 +0200
parents a6360e68134a
children 25bb577878e8
line wrap: on
line diff
--- a/gen/toobj.c	Thu Oct 04 07:35:02 2007 +0200
+++ b/gen/toobj.c	Thu Oct 04 09:24:15 2007 +0200
@@ -145,10 +145,17 @@
 /// Returns the LLVM style index from a DMD style offset
 void AggregateDeclaration::offsetToIndex(unsigned os, std::vector<unsigned>& result)
 {
+    //Logger::println("checking for offset %u :", os);
+    LOG_SCOPE;
     unsigned vos = 0;
     for (unsigned i=0; i<fields.dim; ++i) {
         VarDeclaration* vd = (VarDeclaration*)fields.data[i];
-        if (vd->type->ty == Tstruct) {
+        //Logger::println("found %u", vd->offset);
+        if (os == vd->offset) {
+            result.push_back(i);
+            return;
+        }
+        else if (vd->type->ty == Tstruct) {
             if (vos + vd->type->size() > os) {
                 TypeStruct* ts = (TypeStruct*)vd->type;
                 StructDeclaration* sd = ts->sym;
@@ -157,10 +164,6 @@
                 return;
             }
         }
-        else if (os == vd->offset) {
-            result.push_back(i);
-            return;
-        }
         vos += vd->offset;
     }
     assert(0 && "Offset not found in any aggregate field");
@@ -235,6 +238,12 @@
         }
     }
 
+    if (gIR->topstruct().fields.empty())
+    {
+        gIR->topstruct().fields.push_back(llvm::Type::Int8Ty);
+        gIR->topstruct().inits.push_back(llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false));
+    }
+
     llvm::StructType* structtype = llvm::StructType::get(gIR->topstruct().fields);
 
     // refine abstract types for stuff like: struct S{S* next;}