Skip to content

Commit 1f920ed

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 f9d39ca commit 1f920ed

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

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

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

337346
std::string CodeViewDebug::getFullyQualifiedName(const DIScope *Ty) {
@@ -1487,8 +1496,8 @@ void CodeViewDebug::addToUDTs(const DIType *Ty) {
14871496
const DISubprogram *ClosestSubprogram =
14881497
collectParentScopeNames(Ty->getScope(), ParentScopeNames);
14891498

1490-
std::string FullyQualifiedName =
1491-
formatNestedName(ParentScopeNames, getPrettyScopeName(Ty));
1499+
std::string FullyQualifiedName = formatNestedName(
1500+
ParentScopeNames, getPrettyScopeName(Ty), getScopeSeparator());
14921501

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

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

0 commit comments

Comments
 (0)