Skip to content

Commit d906463

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 63daa84 commit d906463

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
@@ -332,17 +332,26 @@ const DISubprogram *CodeViewDebug::collectParentScopeNames(
332332
}
333333

334334
static std::string formatNestedName(ArrayRef<StringRef> QualifiedNameComponents,
335-
StringRef TypeName) {
335+
StringRef TypeName,
336+
const std::string &Separator) {
336337
std::string FullyQualifiedName;
337338
for (StringRef QualifiedNameComponent :
338339
llvm::reverse(QualifiedNameComponents)) {
339340
FullyQualifiedName.append(std::string(QualifiedNameComponent));
340-
FullyQualifiedName.append("::");
341+
FullyQualifiedName.append(Separator);
341342
}
342343
FullyQualifiedName.append(std::string(TypeName));
343344
return FullyQualifiedName;
344345
}
345346

347+
// Added for LDC: use `.` as scope separator for compile units with D language
348+
// tag.
349+
const char *CodeViewDebug::getScopeSeparator() const {
350+
NamedMDNode *CUs = MMI->getModule()->getNamedMetadata("llvm.dbg.cu");
351+
const DICompileUnit *CU = cast<DICompileUnit>(*CUs->operands().begin());
352+
return CU->getSourceLanguage() == dwarf::DW_LANG_D ? "." : "::";
353+
}
354+
346355
struct CodeViewDebug::TypeLoweringScope {
347356
TypeLoweringScope(CodeViewDebug &CVD) : CVD(CVD) { ++CVD.TypeEmissionLevel; }
348357
~TypeLoweringScope() {
@@ -363,7 +372,7 @@ std::string CodeViewDebug::getFullyQualifiedName(const DIScope *Scope,
363372
TypeLoweringScope S(*this);
364373
SmallVector<StringRef, 5> QualifiedNameComponents;
365374
collectParentScopeNames(Scope, QualifiedNameComponents);
366-
return formatNestedName(QualifiedNameComponents, Name);
375+
return formatNestedName(QualifiedNameComponents, Name, getScopeSeparator());
367376
}
368377

369378
std::string CodeViewDebug::getFullyQualifiedName(const DIScope *Ty) {
@@ -1493,8 +1502,8 @@ void CodeViewDebug::addToUDTs(const DIType *Ty) {
14931502
const DISubprogram *ClosestSubprogram =
14941503
collectParentScopeNames(Ty->getScope(), ParentScopeNames);
14951504

1496-
std::string FullyQualifiedName =
1497-
formatNestedName(ParentScopeNames, getPrettyScopeName(Ty));
1505+
std::string FullyQualifiedName = formatNestedName(
1506+
ParentScopeNames, getPrettyScopeName(Ty), getScopeSeparator());
14981507

14991508
if (ClosestSubprogram == nullptr) {
15001509
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
@@ -287,6 +287,9 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase {
287287
LocalUDTs.clear();
288288
}
289289

290+
// LDC
291+
const char *getScopeSeparator() const;
292+
290293
/// Emit the magic version number at the start of a CodeView type or symbol
291294
/// section. Appears at the front of every .debug$S or .debug$T or .debug$P
292295
/// section.

0 commit comments

Comments
 (0)