summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/AsmPrinter
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp41
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h10
2 files changed, 35 insertions, 16 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
index 4346803738b..8879f6b1f3e 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -1099,10 +1099,25 @@ void CodeViewDebug::beginFunctionImpl(const MachineFunction *MF) {
}
}
-void CodeViewDebug::addToUDTs(const DIType *Ty, TypeIndex TI) {
+static bool shouldEmitUdt(const DIType *T) {
+ while (true) {
+ if (!T || T->isForwardDecl())
+ return false;
+
+ const DIDerivedType *DT = dyn_cast<DIDerivedType>(T);
+ if (!DT)
+ return true;
+ T = DT->getBaseType().resolve();
+ }
+ return true;
+}
+
+void CodeViewDebug::addToUDTs(const DIType *Ty) {
// Don't record empty UDTs.
if (Ty->getName().empty())
return;
+ if (!shouldEmitUdt(Ty))
+ return;
SmallVector<StringRef, 5> QualifiedNameComponents;
const DISubprogram *ClosestSubprogram = getQualifiedNameComponents(
@@ -1111,10 +1126,11 @@ void CodeViewDebug::addToUDTs(const DIType *Ty, TypeIndex TI) {
std::string FullyQualifiedName =
getQualifiedName(QualifiedNameComponents, getPrettyScopeName(Ty));
- if (ClosestSubprogram == nullptr)
- GlobalUDTs.emplace_back(std::move(FullyQualifiedName), TI);
- else if (ClosestSubprogram == CurrentSubprogram)
- LocalUDTs.emplace_back(std::move(FullyQualifiedName), TI);
+ if (ClosestSubprogram == nullptr) {
+ GlobalUDTs.emplace_back(std::move(FullyQualifiedName), Ty);
+ } else if (ClosestSubprogram == CurrentSubprogram) {
+ LocalUDTs.emplace_back(std::move(FullyQualifiedName), Ty);
+ }
// TODO: What if the ClosestSubprogram is neither null or the current
// subprogram? Currently, the UDT just gets dropped on the floor.
@@ -1172,7 +1188,7 @@ TypeIndex CodeViewDebug::lowerTypeAlias(const DIDerivedType *Ty) {
TypeIndex UnderlyingTypeIndex = getTypeIndex(UnderlyingTypeRef);
StringRef TypeName = Ty->getName();
- addToUDTs(Ty, UnderlyingTypeIndex);
+ addToUDTs(Ty);
if (UnderlyingTypeIndex == TypeIndex(SimpleTypeKind::Int32Long) &&
TypeName == "HRESULT")
@@ -1764,7 +1780,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeClass(const DICompositeType *Ty) {
TypeTable.writeKnownType(USLR);
}
- addToUDTs(Ty, ClassTI);
+ addToUDTs(Ty);
return ClassTI;
}
@@ -1803,7 +1819,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeUnion(const DICompositeType *Ty) {
UdtSourceLineRecord USLR(UnionTI, SIRI, Ty->getLine());
TypeTable.writeKnownType(USLR);
- addToUDTs(Ty, UnionTI);
+ addToUDTs(Ty);
return UnionTI;
}
@@ -2203,8 +2219,11 @@ void CodeViewDebug::endCVSubsection(MCSymbol *EndLabel) {
}
void CodeViewDebug::emitDebugInfoForUDTs(
- ArrayRef<std::pair<std::string, TypeIndex>> UDTs) {
- for (const std::pair<std::string, codeview::TypeIndex> &UDT : UDTs) {
+ ArrayRef<std::pair<std::string, const DIType *>> UDTs) {
+ for (const auto &UDT : UDTs) {
+ const DIType *T = UDT.second;
+ assert(shouldEmitUdt(T));
+
MCSymbol *UDTRecordBegin = MMI->getContext().createTempSymbol(),
*UDTRecordEnd = MMI->getContext().createTempSymbol();
OS.AddComment("Record length");
@@ -2215,7 +2234,7 @@ void CodeViewDebug::emitDebugInfoForUDTs(
OS.EmitIntValue(unsigned(SymbolKind::S_UDT), 2);
OS.AddComment("Type");
- OS.EmitIntValue(UDT.second.getIndex(), 4);
+ OS.EmitIntValue(getCompleteTypeIndex(T).getIndex(), 4);
emitNullTerminatedSymbolName(OS, UDT.first);
OS.EmitLabel(UDTRecordEnd);
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
index fd8f60425c2..91f691c635e 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
@@ -187,8 +187,8 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase {
// The UDTs we have seen while processing types; each entry is a pair of type
// index and type name.
- std::vector<std::pair<std::string, codeview::TypeIndex>> LocalUDTs,
- GlobalUDTs;
+ std::vector<std::pair<std::string, const DIType *>> LocalUDTs;
+ std::vector<std::pair<std::string, const DIType *>> GlobalUDTs;
using FileToFilepathMapTy = std::map<const DIFile *, std::string>;
FileToFilepathMapTy FileToFilepathMap;
@@ -222,8 +222,8 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase {
void emitDebugInfoForRetainedTypes();
- void emitDebugInfoForUDTs(
- ArrayRef<std::pair<std::string, codeview::TypeIndex>> UDTs);
+ void
+ emitDebugInfoForUDTs(ArrayRef<std::pair<std::string, const DIType *>> UDTs);
void emitDebugInfoForGlobal(const DIGlobalVariable *DIGV,
const GlobalVariable *GV, MCSymbol *GVSym);
@@ -266,7 +266,7 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase {
codeview::TypeIndex getVBPTypeIndex();
- void addToUDTs(const DIType *Ty, codeview::TypeIndex TI);
+ void addToUDTs(const DIType *Ty);
codeview::TypeIndex lowerType(const DIType *Ty, const DIType *ClassTy);
codeview::TypeIndex lowerTypeAlias(const DIDerivedType *Ty);
OpenPOWER on IntegriCloud