diff options
Diffstat (limited to 'src/ortho/llvm6/llvm-cbindings.cpp')
-rw-r--r-- | src/ortho/llvm6/llvm-cbindings.cpp | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/src/ortho/llvm6/llvm-cbindings.cpp b/src/ortho/llvm6/llvm-cbindings.cpp index 98470d8fa..2f5cebe83 100644 --- a/src/ortho/llvm6/llvm-cbindings.cpp +++ b/src/ortho/llvm6/llvm-cbindings.cpp @@ -376,8 +376,12 @@ struct OTnodeBase { DIType *Dbg; #endif + // Kind of type. OTKind Kind; + + // If true, the type is bounded: all the elements have a defined size. bool Bounded; + OTnodeBase (LLVMTypeRef R, OTKind K, bool Bounded) : Ref(R), #ifdef USE_DEBUG @@ -643,7 +647,7 @@ struct OElementList { OFKind Kind; // Number of fields. - unsigned Count; + unsigned BndCount; // For record: the access to the incomplete (but named) type. OTnode RecType; @@ -685,9 +689,10 @@ extern "C" void new_record_field(OElementList *Elements, OFnodeRec **El, OIdent Ident, OTnode Etype) { - *El = new OFnodeRec(Etype, Ident, Elements->Count); + *El = new OFnodeRec(Etype, Ident, Etype->Bounded ? Elements->BndCount : ~0U); Elements->Els->push_back(*El); - Elements->Count++; + if (Etype->Bounded) + Elements->BndCount++; } struct OTnodeRecBase : OTnodeBase { @@ -710,16 +715,19 @@ struct OTnodeIncompleteRec : OTnodeRecBase { static DINodeArray buildDebugRecordElements(OTnodeRecBase *Atype) { - unsigned Count = Atype->Els.size(); - std::vector<Metadata *> els(Count); + std::vector<Metadata *> els; + + els.reserve(Atype->Els.size()); unsigned i = 0; for (OFnodeBase *e : Atype->Els) { - unsigned bitoff = 8 * LLVMOffsetOfElement(TheTargetData, Atype->Ref, i); - els[i++] = DBuilder->createMemberType - (DebugCurrentSubprg, StringRef(e->Ident.cstr), NULL, 0, - e->FType->getBitSize(), /* align */ 0, - bitoff, DINode::DIFlags::FlagZero, e->FType->Dbg); + if (!e->FType->Bounded) + break; + unsigned bitoff = 8 * LLVMOffsetOfElement(TheTargetData, Atype->Ref, i++); + els.push_back(DBuilder->createMemberType + (DebugCurrentSubprg, StringRef(e->Ident.cstr), NULL, 0, + e->FType->getBitSize(), /* align */ 0, + bitoff, DINode::DIFlags::FlagZero, e->FType->Dbg)); } return DBuilder->getOrCreateArray(els); @@ -729,21 +737,24 @@ buildDebugRecordElements(OTnodeRecBase *Atype) extern "C" void finish_record_type(OElementList *Els, OTnode *Res) { - LLVMTypeRef *Types = new LLVMTypeRef[Els->Count]; + LLVMTypeRef *Types = new LLVMTypeRef[Els->BndCount]; // Create types array for elements. int i = 0; bool Bounded = true; for (OFnodeBase *Field : *Els->Els) { - Bounded &= Field->FType->Bounded; - Types[i++] = Field->FType->Ref; + if (Field->FType->Bounded) + Types[i++] = Field->FType->Ref; + else + Bounded = false; } + assert(i == Els->BndCount); OTnodeRecBase *T; if (Els->RecType != nullptr) { // Completion - LLVMStructSetBody (Els->RecType->Ref, Types, Els->Count, 0); + LLVMStructSetBody (Els->RecType->Ref, Types, Els->BndCount, 0); Els->RecType->Bounded = Bounded; T = static_cast<OTnodeRecBase *>(Els->RecType); T->Els = std::move(*Els->Els); @@ -762,7 +773,7 @@ finish_record_type(OElementList *Els, OTnode *Res) } else { // Non-completion. // Debug info are created when the type is declared. - T = new OTnodeRec(LLVMStructType(Types, Els->Count, 0), Bounded); + T = new OTnodeRec(LLVMStructType(Types, Els->BndCount, 0), Bounded); T->Els = std::move(*Els->Els); } *Res = T; |