Skip to content

Commit 63267ed

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 de3d950 commit 63267ed

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
@@ -301,17 +301,26 @@ const DISubprogram *CodeViewDebug::collectParentScopeNames(
301301
}
302302

303303
static std::string formatNestedName(ArrayRef<StringRef> QualifiedNameComponents,
304-
StringRef TypeName) {
304+
StringRef TypeName,
305+
const std::string &Separator) {
305306
std::string FullyQualifiedName;
306307
for (StringRef QualifiedNameComponent :
307308
llvm::reverse(QualifiedNameComponents)) {
308309
FullyQualifiedName.append(std::string(QualifiedNameComponent));
309-
FullyQualifiedName.append("::");
310+
FullyQualifiedName.append(Separator);
310311
}
311312
FullyQualifiedName.append(std::string(TypeName));
312313
return FullyQualifiedName;
313314
}
314315

316+
// Added for LDC: use `.` as scope separator for compile units with D language
317+
// tag.
318+
const char *CodeViewDebug::getScopeSeparator() const {
319+
NamedMDNode *CUs = MMI->getModule()->getNamedMetadata("llvm.dbg.cu");
320+
const DICompileUnit *CU = cast<DICompileUnit>(*CUs->operands().begin());
321+
return CU->getSourceLanguage() == dwarf::DW_LANG_D ? "." : "::";
322+
}
323+
315324
struct CodeViewDebug::TypeLoweringScope {
316325
TypeLoweringScope(CodeViewDebug &CVD) : CVD(CVD) { ++CVD.TypeEmissionLevel; }
317326
~TypeLoweringScope() {
@@ -332,7 +341,7 @@ std::string CodeViewDebug::getFullyQualifiedName(const DIScope *Scope,
332341
TypeLoweringScope S(*this);
333342
SmallVector<StringRef, 5> QualifiedNameComponents;
334343
collectParentScopeNames(Scope, QualifiedNameComponents);
335-
return formatNestedName(QualifiedNameComponents, Name);
344+
return formatNestedName(QualifiedNameComponents, Name, getScopeSeparator());
336345
}
337346

338347
std::string CodeViewDebug::getFullyQualifiedName(const DIScope *Ty) {
@@ -1604,8 +1613,8 @@ void CodeViewDebug::addToUDTs(const DIType *Ty) {
16041613
const DISubprogram *ClosestSubprogram =
16051614
collectParentScopeNames(Ty->getScope(), ParentScopeNames);
16061615

1607-
std::string FullyQualifiedName =
1608-
formatNestedName(ParentScopeNames, getPrettyScopeName(Ty));
1616+
std::string FullyQualifiedName = formatNestedName(
1617+
ParentScopeNames, getPrettyScopeName(Ty), getScopeSeparator());
16091618

16101619
if (ClosestSubprogram == nullptr) {
16111620
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
@@ -293,6 +293,9 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase {
293293
LocalUDTs.clear();
294294
}
295295

296+
// LDC
297+
const char *getScopeSeparator() const;
298+
296299
/// Emit the magic version number at the start of a CodeView type or symbol
297300
/// section. Appears at the front of every .debug$S or .debug$T or .debug$P
298301
/// section.

0 commit comments

Comments
 (0)