mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-03-05 03:43:13 +01:00
Fix SymOffExp::toConstElem.
I am surprised and horrified at the same time that the test suite (on platforms other than Windows, where the code path is triggered in core.stdc.stdio) did not catch this at all. The elemSize-dependent path probably doesn't make too much sense for global variables, as it always refers to the total size of the global. Should add a special case for arrays for clearer codegen in those cases. GitHub: Fixes #477.
This commit is contained in:
@@ -1262,7 +1262,7 @@ DValue* SymOffExp::toElem(IRState* p)
|
||||
|
||||
llvm::Constant* SymOffExp::toConstElem(IRState* p)
|
||||
{
|
||||
Logger::print("SymOffExp::toConstElem: %s @ %s\n", toChars(), type->toChars());
|
||||
IF_LOG Logger::println("SymOffExp::toConstElem: %s @ %s", toChars(), type->toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
// We might get null here due to the hackish implementation of
|
||||
@@ -1277,8 +1277,11 @@ llvm::Constant* SymOffExp::toConstElem(IRState* p)
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t elemSize = gDataLayout->getTypeStoreSize(
|
||||
const unsigned elemSize = gDataLayout->getTypeStoreSize(
|
||||
base->getType()->getContainedType(0));
|
||||
|
||||
Logger::println("adding offset: %u (elem size: %u)", offset, elemSize);
|
||||
|
||||
if (offset % elemSize == 0)
|
||||
{
|
||||
// We can turn this into a "nice" GEP.
|
||||
@@ -1291,7 +1294,7 @@ llvm::Constant* SymOffExp::toConstElem(IRState* p)
|
||||
// apply the byte offset.
|
||||
result = llvm::ConstantExpr::getGetElementPtr(
|
||||
DtoBitCast(base, getVoidPtrType()),
|
||||
DtoConstSize_t(offset / elemSize));
|
||||
DtoConstSize_t(offset));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user