Skip to content

Commit e86602a

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 54fd506 commit e86602a

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
@@ -297,17 +297,26 @@ const DISubprogram *CodeViewDebug::collectParentScopeNames(
297297
}
298298

299299
static std::string formatNestedName(ArrayRef<StringRef> QualifiedNameComponents,
300-
StringRef TypeName) {
300+
StringRef TypeName,
301+
const std::string &Separator) {
301302
std::string FullyQualifiedName;
302303
for (StringRef QualifiedNameComponent :
303304
llvm::reverse(QualifiedNameComponents)) {
304305
FullyQualifiedName.append(std::string(QualifiedNameComponent));
305-
FullyQualifiedName.append("::");
306+
FullyQualifiedName.append(Separator);
306307
}
307308
FullyQualifiedName.append(std::string(TypeName));
308309
return FullyQualifiedName;
309310
}
310311

312+
// Added for LDC: use `.` as scope separator for compile units with D language
313+
// tag.
314+
const char *CodeViewDebug::getScopeSeparator() const {
315+
NamedMDNode *CUs = MMI->getModule()->getNamedMetadata("llvm.dbg.cu");
316+
const DICompileUnit *CU = cast<DICompileUnit>(*CUs->operands().begin());
317+
return CU->getSourceLanguage() == dwarf::DW_LANG_D ? "." : "::";
318+
}
319+
311320
struct CodeViewDebug::TypeLoweringScope {
312321
TypeLoweringScope(CodeViewDebug &CVD) : CVD(CVD) { ++CVD.TypeEmissionLevel; }
313322
~TypeLoweringScope() {
@@ -328,7 +337,7 @@ std::string CodeViewDebug::getFullyQualifiedName(const DIScope *Scope,
328337
TypeLoweringScope S(*this);
329338
SmallVector<StringRef, 5> QualifiedNameComponents;
330339
collectParentScopeNames(Scope, QualifiedNameComponents);
331-
return formatNestedName(QualifiedNameComponents, Name);
340+
return formatNestedName(QualifiedNameComponents, Name, getScopeSeparator());
332341
}
333342

334343
std::string CodeViewDebug::getFullyQualifiedName(const DIScope *Ty) {
@@ -1640,8 +1649,8 @@ void CodeViewDebug::addToUDTs(const DIType *Ty) {
16401649
const DISubprogram *ClosestSubprogram =
16411650
collectParentScopeNames(Ty->getScope(), ParentScopeNames);
16421651

1643-
std::string FullyQualifiedName =
1644-
formatNestedName(ParentScopeNames, getPrettyScopeName(Ty));
1652+
std::string FullyQualifiedName = formatNestedName(
1653+
ParentScopeNames, getPrettyScopeName(Ty), getScopeSeparator());
16451654

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

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h

+3
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase {
320320
LocalUDTs.clear();
321321
}
322322

323+
// LDC
324+
const char *getScopeSeparator() const;
325+
323326
/// Emit the magic version number at the start of a CodeView type or symbol
324327
/// section. Appears at the front of every .debug$S or .debug$T or .debug$P
325328
/// section.

0 commit comments

Comments
 (0)