mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-09 12:32:33 +03:00
[fix: handle unsized IR field types]
This commit is contained in:
parent
bd5fab1f06
commit
372d6b4983
3 changed files with 7 additions and 24 deletions
|
@ -1321,24 +1321,6 @@ void DtoSetFuncDeclIntrinsicName(TemplateInstance *ti, TemplateDeclaration *td,
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
size_t getMemberSize(Type *type) {
|
|
||||||
const dinteger_t dSize = type->size();
|
|
||||||
llvm::Type *const llType = DtoType(type);
|
|
||||||
if (!llType->isSized()) {
|
|
||||||
// Forward reference in a cycle or similar, we need to trust the D type.
|
|
||||||
return dSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint64_t llSize = gDataLayout->getTypeAllocSize(llType);
|
|
||||||
assert(llSize <= dSize &&
|
|
||||||
"LLVM type is bigger than the corresponding D type, "
|
|
||||||
"might lead to aggregate layout mismatch.");
|
|
||||||
|
|
||||||
return llSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
Type *stripModifiers(Type *type, bool transitive) {
|
Type *stripModifiers(Type *type, bool transitive) {
|
||||||
if (type->ty == TY::Tfunction) {
|
if (type->ty == TY::Tfunction) {
|
||||||
return type;
|
return type;
|
||||||
|
|
|
@ -152,10 +152,6 @@ llvm::CallInst *DtoInlineAsmExpr(const Loc &loc, llvm::StringRef code,
|
||||||
llvm::ArrayRef<llvm::Value *> operands,
|
llvm::ArrayRef<llvm::Value *> operands,
|
||||||
llvm::Type *returnType);
|
llvm::Type *returnType);
|
||||||
|
|
||||||
/// Returns the size the LLVM type for a member variable of the given type will
|
|
||||||
/// take up in a struct (in bytes). This does not include padding in any way.
|
|
||||||
size_t getMemberSize(Type *type);
|
|
||||||
|
|
||||||
/// Returns the llvm::Value of the passed DValue, making sure that it is an
|
/// Returns the llvm::Value of the passed DValue, making sure that it is an
|
||||||
/// lvalue (has a memory address), so it can be passed to the D runtime
|
/// lvalue (has a memory address), so it can be passed to the D runtime
|
||||||
/// functions without problems.
|
/// functions without problems.
|
||||||
|
|
|
@ -86,7 +86,7 @@ void AggrTypeBuilder::addAggregate(
|
||||||
LLSmallVector<BitFieldDeclaration *, 16> allBitFieldDecls;
|
LLSmallVector<BitFieldDeclaration *, 16> allBitFieldDecls;
|
||||||
for (VarDeclaration *field : ad->fields) {
|
for (VarDeclaration *field : ad->fields) {
|
||||||
if (auto bf = field->isBitFieldDeclaration()) {
|
if (auto bf = field->isBitFieldDeclaration()) {
|
||||||
printf(".: %s: byte offset %d, bit offset %d, type size %d\n", bf->toChars(), bf->offset, bf->bitOffset, (int) bf->type->size());
|
//printf(".: %s: byte offset %d, bit offset %d, type size %d\n", bf->toChars(), bf->offset, bf->bitOffset, (int) bf->type->size());
|
||||||
allBitFieldDecls.push_back(bf);
|
allBitFieldDecls.push_back(bf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,12 @@ void AggrTypeBuilder::addAggregate(
|
||||||
m_defaultTypes.push_back(fieldType);
|
m_defaultTypes.push_back(fieldType);
|
||||||
|
|
||||||
// advance offset to right past this field
|
// advance offset to right past this field
|
||||||
m_offset += getTypeAllocSize(fieldType); //getMemberSize(vd->type);
|
if (!fieldType->isSized()) {
|
||||||
|
// forward reference in a cycle or similar, we need to trust the D type
|
||||||
|
m_offset += vd->type->size();
|
||||||
|
} else {
|
||||||
|
m_offset += getTypeAllocSize(fieldType);
|
||||||
|
}
|
||||||
|
|
||||||
// set the field index
|
// set the field index
|
||||||
m_varGEPIndices[vd] = m_fieldIndex;
|
m_varGEPIndices[vd] = m_fieldIndex;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue