comparison gen/llvmhelpers.cpp @ 1351:8d501abecd24

Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
author Tomas Lindquist Olsen <tomas.l.olsen gmail com>
date Thu, 14 May 2009 17:20:17 +0200
parents 15e9762bb620
children b9f5f7c5db73
comparison
equal deleted inserted replaced
1350:15e9762bb620 1351:8d501abecd24
1438 M->ir.irModule = new IrModule(M, M->srcfile->toChars()); 1438 M->ir.irModule = new IrModule(M, M->srcfile->toChars());
1439 return M->ir.irModule; 1439 return M->ir.irModule;
1440 } 1440 }
1441 1441
1442 ////////////////////////////////////////////////////////////////////////////////////////// 1442 //////////////////////////////////////////////////////////////////////////////////////////
1443
1444 size_t realignOffset(size_t offset, Type* type)
1445 {
1446 size_t alignsize = type->alignsize();
1447 size_t alignedoffset = (offset + alignsize - 1) & ~(alignsize - 1);
1448
1449 // if the aligned offset already matches the input offset
1450 // don't waste time checking things are ok!
1451 if (alignedoffset == offset)
1452 return alignedoffset;
1453
1454 // disabled since this can fail for opaques. if the check above is not in place
1455 // it does so for gcx.d!!!
1456 // this needs to be investigated, but I don't have time right now!
1457 #if 0
1458 // if not, we have to make sure it agrees with what llvm thinks is the alignment
1459 // sometimes this is different from what we really need (in case of unions, see #294)
1460 // so if there we get different results we don't realign the offset at all and instead
1461 // just return the original offset, and rely on the users to insert padding manually.
1462 IF_LOG Logger::cout() << "getting alignment for type " << type->toChars()
1463 << " with llvm type " << *DtoType(type) << std::endl;
1464 size_t alignsize2 = gTargetData->getABITypeAlignment(DtoType(type));
1465
1466 if (alignsize != alignsize2)
1467 {
1468 assert(alignsize > alignsize2 && "this is not good, the D and LLVM "
1469 "type alignments differ, but LLVM's is bigger! This will break "
1470 "the type mapping algorithms");
1471 // don't try and align the offset, and let the mappers pad 100% manually
1472 return offset;
1473 }
1474 #endif
1475
1476 return alignedoffset;
1477 }
1478
1479 //////////////////////////////////////////////////////////////////////////////////////////