Skip to content

Commit 88365ac

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 10a4b26 commit 88365ac

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

+14-5
Original file line numberDiff line numberDiff line change
@@ -293,17 +293,26 @@ const DISubprogram *CodeViewDebug::collectParentScopeNames(
293293
}
294294

295295
static std::string formatNestedName(ArrayRef<StringRef> QualifiedNameComponents,
296-
StringRef TypeName) {
296+
StringRef TypeName,
297+
const std::string &Separator) {
297298
std::string FullyQualifiedName;
298299
for (StringRef QualifiedNameComponent :
299300
llvm::reverse(QualifiedNameComponents)) {
300301
FullyQualifiedName.append(std::string(QualifiedNameComponent));
301-
FullyQualifiedName.append("::");
302+
FullyQualifiedName.append(Separator);
302303
}
303304
FullyQualifiedName.append(std::string(TypeName));
304305
return FullyQualifiedName;
305306
}
306307

308+
// Added for LDC: use `.` as scope separator for compile units with D language
309+
// tag.
310+
const char *CodeViewDebug::getScopeSeparator() const {
311+
NamedMDNode *CUs = MMI->getModule()->getNamedMetadata("llvm.dbg.cu");
312+
const DICompileUnit *CU = cast<DICompileUnit>(*CUs->operands().begin());
313+
return CU->getSourceLanguage() == dwarf::DW_LANG_D ? "." : "::";
314+
}
315+
307316
struct CodeViewDebug::TypeLoweringScope {
308317
TypeLoweringScope(CodeViewDebug &CVD) : CVD(CVD) { ++CVD.TypeEmissionLevel; }
309318
~TypeLoweringScope() {
@@ -324,7 +333,7 @@ std::string CodeViewDebug::getFullyQualifiedName(const DIScope *Scope,
324333
TypeLoweringScope S(*this);
325334
SmallVector<StringRef, 5> QualifiedNameComponents;
326335
collectParentScopeNames(Scope, QualifiedNameComponents);
327-
return formatNestedName(QualifiedNameComponents, Name);
336+
return formatNestedName(QualifiedNameComponents, Name, getScopeSeparator());
328337
}
329338

330339
std::string CodeViewDebug::getFullyQualifiedName(const DIScope *Ty) {
@@ -1622,8 +1631,8 @@ void CodeViewDebug::addToUDTs(const DIType *Ty) {
16221631
const DISubprogram *ClosestSubprogram =
16231632
collectParentScopeNames(Ty->getScope(), ParentScopeNames);
16241633

1625-
std::string FullyQualifiedName =
1626-
formatNestedName(ParentScopeNames, getPrettyScopeName(Ty));
1634+
std::string FullyQualifiedName = formatNestedName(
1635+
ParentScopeNames, getPrettyScopeName(Ty), getScopeSeparator());
16271636

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

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h

+3
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase {
304304
LocalUDTs.clear();
305305
}
306306

307+
// LDC
308+
const char *getScopeSeparator() const;
309+
307310
/// Emit the magic version number at the start of a CodeView type or symbol
308311
/// section. Appears at the front of every .debug$S or .debug$T or .debug$P
309312
/// section.

0 commit comments

Comments
 (0)