changeset 1356:59c2aa9def23

Enabled fix for ticket #294 . It will try it's best to let LLVM handle the alignment, and fall back to manual padding when that's not possible. If this causes problems again, we'll have to consistently pad manually using packed structs.
author Tomas Lindquist Olsen <tomas.l.olsen gmail com>
date Fri, 15 May 2009 17:05:35 +0200
parents c5410f294c89
children 48747003a5de
files gen/llvmhelpers.cpp
diffstat 1 files changed, 13 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/gen/llvmhelpers.cpp	Fri May 15 15:30:59 2009 +0200
+++ b/gen/llvmhelpers.cpp	Fri May 15 17:05:35 2009 +0200
@@ -1451,28 +1451,28 @@
     if (alignedoffset == offset)
         return alignedoffset;
 
-    // disabled since this can fail for opaques. if the check above is not in place
-    // it does so for gcx.d!!!
-    // this needs to be investigated, but I don't have time right now!
-#if 0
-    // if not, we have to make sure it agrees with what llvm thinks is the alignment
-    // sometimes this is different from what we really need (in case of unions, see #294)
-    // so if there we get different results we don't realign the offset at all and instead
-    // just return the original offset, and rely on the users to insert padding manually.
-    IF_LOG Logger::cout() << "getting alignment for type " << type->toChars()
-        << " with llvm type " << *DtoType(type) << std::endl;
-    size_t alignsize2 = gTargetData->getABITypeAlignment(DtoType(type));
+    // we cannot get the llvm alignment if the type is still opaque, this can happen in some
+    // forward reference situations, so when this happens we fall back to manual padding.
+    const llvm::Type* T = DtoType(type);
+    if (llvm::isa<llvm::OpaqueType>(T))
+    {
+        return offset;
+    }
 
+    // then we check against the llvm alignment
+    size_t alignsize2 = gTargetData->getABITypeAlignment(T);
+
+    // if it differs we need to insert manual padding as well
     if (alignsize != alignsize2)
     {
         assert(alignsize > alignsize2 && "this is not good, the D and LLVM "
             "type alignments differ, but LLVM's is bigger! This will break "
-            "the type mapping algorithms");
+            "aggregate type mapping");
         // don't try and align the offset, and let the mappers pad 100% manually
         return offset;
     }
-#endif
 
+    // ok, we're good, llvm will align properly!
     return alignedoffset;
 }