# HG changeset patch # User Tomas Lindquist Olsen # Date 1242399935 -7200 # Node ID 59c2aa9def233126a535728604019dd23723d02f # Parent c5410f294c8985a4c2acdc4b71643e9e57c2cd85 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. diff -r c5410f294c89 -r 59c2aa9def23 gen/llvmhelpers.cpp --- 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(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; }