Skip to content

Commit 310b277

Browse files
committed
[LDC] Use . instead of :: as CodeView DI scope separator
For compile units with D language tag, i.e., if compiled with `-g`.
1 parent a0ab2a6 commit 310b277

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,17 +299,26 @@ const DISubprogram *CodeViewDebug::collectParentScopeNames(
299299
}
300300

301301
static std::string formatNestedName(ArrayRef<StringRef> QualifiedNameComponents,
302-
StringRef TypeName) {
302+
StringRef TypeName,
303+
const std::string &Separator) {
303304
std::string FullyQualifiedName;
304305
for (StringRef QualifiedNameComponent :
305306
llvm::reverse(QualifiedNameComponents)) {
306307
FullyQualifiedName.append(std::string(QualifiedNameComponent));
307-
FullyQualifiedName.append("::");
308+
FullyQualifiedName.append(Separator);
308309
}
309310
FullyQualifiedName.append(std::string(TypeName));
310311
return FullyQualifiedName;
311312
}
312313

314+
// Added for LDC: use `.` as scope separator for compile units with D language
315+
// tag.
316+
const char *CodeViewDebug::getScopeSeparator() const {
317+
NamedMDNode *CUs = MMI->getModule()->getNamedMetadata("llvm.dbg.cu");
318+
const DICompileUnit *CU = cast<DICompileUnit>(*CUs->operands().begin());
319+
return CU->getSourceLanguage() == dwarf::DW_LANG_D ? "." : "::";
320+
}
321+
313322
struct CodeViewDebug::TypeLoweringScope {
314323
TypeLoweringScope(CodeViewDebug &CVD) : CVD(CVD) { ++CVD.TypeEmissionLevel; }
315324
~TypeLoweringScope() {
@@ -330,7 +339,7 @@ std::string CodeViewDebug::getFullyQualifiedName(const DIScope *Scope,
330339
TypeLoweringScope S(*this);
331340
SmallVector<StringRef, 5> QualifiedNameComponents;
332341
collectParentScopeNames(Scope, QualifiedNameComponents);
333-
return formatNestedName(QualifiedNameComponents, Name);
342+
return formatNestedName(QualifiedNameComponents, Name, getScopeSeparator());
334343
}
335344

336345
std::string CodeViewDebug::getFullyQualifiedName(const DIScope *Ty) {
@@ -1654,8 +1663,8 @@ void CodeViewDebug::addToUDTs(const DIType *Ty) {
16541663
const DISubprogram *ClosestSubprogram =
16551664
collectParentScopeNames(Ty->getScope(), ParentScopeNames);
16561665

1657-
std::string FullyQualifiedName =
1658-
formatNestedName(ParentScopeNames, getPrettyScopeName(Ty));
1666+
std::string FullyQualifiedName = formatNestedName(
1667+
ParentScopeNames, getPrettyScopeName(Ty), getScopeSeparator());
16591668

16601669
if (ClosestSubprogram == nullptr) {
16611670
GlobalUDTs.emplace_back(std::move(FullyQualifiedName), Ty);

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase {
325325
LocalUDTs.clear();
326326
}
327327

328+
// LDC
329+
const char *getScopeSeparator() const;
330+
328331
/// Emit the magic version number at the start of a CodeView type or symbol
329332
/// section. Appears at the front of every .debug$S or .debug$T or .debug$P
330333
/// section.

0 commit comments

Comments
 (0)