Mercurial > projects > ldc
comparison gen/llvmhelpers.cpp @ 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 | e5c5d354c649 |
comparison
equal
deleted
inserted
replaced
1355:c5410f294c89 | 1356:59c2aa9def23 |
---|---|
1449 // if the aligned offset already matches the input offset | 1449 // if the aligned offset already matches the input offset |
1450 // don't waste time checking things are ok! | 1450 // don't waste time checking things are ok! |
1451 if (alignedoffset == offset) | 1451 if (alignedoffset == offset) |
1452 return alignedoffset; | 1452 return alignedoffset; |
1453 | 1453 |
1454 // disabled since this can fail for opaques. if the check above is not in place | 1454 // we cannot get the llvm alignment if the type is still opaque, this can happen in some |
1455 // it does so for gcx.d!!! | 1455 // forward reference situations, so when this happens we fall back to manual padding. |
1456 // this needs to be investigated, but I don't have time right now! | 1456 const llvm::Type* T = DtoType(type); |
1457 #if 0 | 1457 if (llvm::isa<llvm::OpaqueType>(T)) |
1458 // if not, we have to make sure it agrees with what llvm thinks is the alignment | 1458 { |
1459 // sometimes this is different from what we really need (in case of unions, see #294) | 1459 return offset; |
1460 // so if there we get different results we don't realign the offset at all and instead | 1460 } |
1461 // just return the original offset, and rely on the users to insert padding manually. | 1461 |
1462 IF_LOG Logger::cout() << "getting alignment for type " << type->toChars() | 1462 // then we check against the llvm alignment |
1463 << " with llvm type " << *DtoType(type) << std::endl; | 1463 size_t alignsize2 = gTargetData->getABITypeAlignment(T); |
1464 size_t alignsize2 = gTargetData->getABITypeAlignment(DtoType(type)); | 1464 |
1465 | 1465 // if it differs we need to insert manual padding as well |
1466 if (alignsize != alignsize2) | 1466 if (alignsize != alignsize2) |
1467 { | 1467 { |
1468 assert(alignsize > alignsize2 && "this is not good, the D and LLVM " | 1468 assert(alignsize > alignsize2 && "this is not good, the D and LLVM " |
1469 "type alignments differ, but LLVM's is bigger! This will break " | 1469 "type alignments differ, but LLVM's is bigger! This will break " |
1470 "the type mapping algorithms"); | 1470 "aggregate type mapping"); |
1471 // don't try and align the offset, and let the mappers pad 100% manually | 1471 // don't try and align the offset, and let the mappers pad 100% manually |
1472 return offset; | 1472 return offset; |
1473 } | 1473 } |
1474 #endif | 1474 |
1475 | 1475 // ok, we're good, llvm will align properly! |
1476 return alignedoffset; | 1476 return alignedoffset; |
1477 } | 1477 } |
1478 | 1478 |
1479 ////////////////////////////////////////////////////////////////////////////////////////// | 1479 ////////////////////////////////////////////////////////////////////////////////////////// |