Skip to content

Commit 26b5914

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 304786a commit 26b5914

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -318,21 +318,30 @@ static const DISubprogram *getQualifiedNameComponents(
318318
}
319319

320320
static std::string getQualifiedName(ArrayRef<StringRef> QualifiedNameComponents,
321-
StringRef TypeName) {
321+
StringRef TypeName, StringRef Separator) {
322322
std::string FullyQualifiedName;
323323
for (StringRef QualifiedNameComponent :
324324
llvm::reverse(QualifiedNameComponents)) {
325325
FullyQualifiedName.append(QualifiedNameComponent);
326-
FullyQualifiedName.append("::");
326+
FullyQualifiedName.append(Separator);
327327
}
328328
FullyQualifiedName.append(TypeName);
329329
return FullyQualifiedName;
330330
}
331331

332-
static std::string getFullyQualifiedName(const DIScope *Scope, StringRef Name) {
332+
static std::string getFullyQualifiedName(const DIScope *Scope, StringRef Name,
333+
StringRef Separator) {
333334
SmallVector<StringRef, 5> QualifiedNameComponents;
334335
getQualifiedNameComponents(Scope, QualifiedNameComponents);
335-
return getQualifiedName(QualifiedNameComponents, Name);
336+
return getQualifiedName(QualifiedNameComponents, Name, Separator);
337+
}
338+
339+
// Added for LDC: use `.` as scope separator for compile units with D language
340+
// tag.
341+
const char *CodeViewDebug::getScopeSeparator() const {
342+
NamedMDNode *CUs = MMI->getModule()->getNamedMetadata("llvm.dbg.cu");
343+
const DICompileUnit *CU = cast<DICompileUnit>(*CUs->operands().begin());
344+
return CU->getSourceLanguage() == dwarf::DW_LANG_D ? "." : "::";
336345
}
337346

338347
struct CodeViewDebug::TypeLoweringScope {
@@ -347,9 +356,10 @@ struct CodeViewDebug::TypeLoweringScope {
347356
CodeViewDebug &CVD;
348357
};
349358

350-
static std::string getFullyQualifiedName(const DIScope *Ty) {
359+
static std::string getFullyQualifiedName(const DIScope *Ty,
360+
StringRef Separator) {
351361
const DIScope *Scope = Ty->getScope();
352-
return getFullyQualifiedName(Scope, getPrettyScopeName(Ty));
362+
return getFullyQualifiedName(Scope, getPrettyScopeName(Ty), Separator);
353363
}
354364

355365
TypeIndex CodeViewDebug::getScopeIndex(const DIScope *Scope) {
@@ -365,7 +375,7 @@ TypeIndex CodeViewDebug::getScopeIndex(const DIScope *Scope) {
365375
return I->second;
366376

367377
// Build the fully qualified name of the scope.
368-
std::string ScopeName = getFullyQualifiedName(Scope);
378+
std::string ScopeName = getFullyQualifiedName(Scope, getScopeSeparator());
369379
StringIdRecord SID(TypeIndex(), ScopeName);
370380
auto TI = TypeTable.writeLeafType(SID);
371381
return recordTypeIndexForDINode(Scope, TI);
@@ -1002,7 +1012,8 @@ void CodeViewDebug::emitDebugInfoForFunction(const Function *GV,
10021012
// If we have a display name, build the fully qualified name by walking the
10031013
// chain of scopes.
10041014
if (!SP->getName().empty())
1005-
FuncName = getFullyQualifiedName(SP->getScope(), SP->getName());
1015+
FuncName = getFullyQualifiedName(SP->getScope(), SP->getName(),
1016+
getScopeSeparator());
10061017

10071018
// If our DISubprogram name is empty, use the mangled name.
10081019
if (FuncName.empty())
@@ -1472,8 +1483,8 @@ void CodeViewDebug::addToUDTs(const DIType *Ty) {
14721483
const DISubprogram *ClosestSubprogram =
14731484
getQualifiedNameComponents(Ty->getScope(), QualifiedNameComponents);
14741485

1475-
std::string FullyQualifiedName =
1476-
getQualifiedName(QualifiedNameComponents, getPrettyScopeName(Ty));
1486+
std::string FullyQualifiedName = getQualifiedName(
1487+
QualifiedNameComponents, getPrettyScopeName(Ty), getScopeSeparator());
14771488

14781489
if (ClosestSubprogram == nullptr) {
14791490
GlobalUDTs.emplace_back(std::move(FullyQualifiedName), Ty);
@@ -2072,7 +2083,7 @@ TypeIndex CodeViewDebug::lowerTypeEnum(const DICompositeType *Ty) {
20722083
FTI = TypeTable.insertRecord(ContinuationBuilder);
20732084
}
20742085

2075-
std::string FullName = getFullyQualifiedName(Ty);
2086+
std::string FullName = getFullyQualifiedName(Ty, getScopeSeparator());
20762087

20772088
EnumRecord ER(EnumeratorCount, CO, FTI, FullName, Ty->getIdentifier(),
20782089
getTypeIndex(Ty->getBaseType()));
@@ -2223,7 +2234,7 @@ TypeIndex CodeViewDebug::lowerTypeClass(const DICompositeType *Ty) {
22232234
TypeRecordKind Kind = getRecordKind(Ty);
22242235
ClassOptions CO =
22252236
ClassOptions::ForwardReference | getCommonClassOptions(Ty);
2226-
std::string FullName = getFullyQualifiedName(Ty);
2237+
std::string FullName = getFullyQualifiedName(Ty, getScopeSeparator());
22272238
ClassRecord CR(Kind, 0, CO, TypeIndex(), TypeIndex(), TypeIndex(), 0,
22282239
FullName, Ty->getIdentifier());
22292240
TypeIndex FwdDeclTI = TypeTable.writeLeafType(CR);
@@ -2254,7 +2265,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeClass(const DICompositeType *Ty) {
22542265
if (isNonTrivial(Ty))
22552266
CO |= ClassOptions::HasConstructorOrDestructor;
22562267

2257-
std::string FullName = getFullyQualifiedName(Ty);
2268+
std::string FullName = getFullyQualifiedName(Ty, getScopeSeparator());
22582269

22592270
uint64_t SizeInBytes = Ty->getSizeInBits() / 8;
22602271

@@ -2276,7 +2287,7 @@ TypeIndex CodeViewDebug::lowerTypeUnion(const DICompositeType *Ty) {
22762287

22772288
ClassOptions CO =
22782289
ClassOptions::ForwardReference | getCommonClassOptions(Ty);
2279-
std::string FullName = getFullyQualifiedName(Ty);
2290+
std::string FullName = getFullyQualifiedName(Ty, getScopeSeparator());
22802291
UnionRecord UR(0, CO, TypeIndex(), 0, FullName, Ty->getIdentifier());
22812292
TypeIndex FwdDeclTI = TypeTable.writeLeafType(UR);
22822293
if (!Ty->isForwardDecl())
@@ -2296,7 +2307,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeUnion(const DICompositeType *Ty) {
22962307
CO |= ClassOptions::ContainsNestedClass;
22972308

22982309
uint64_t SizeInBytes = Ty->getSizeInBits() / 8;
2299-
std::string FullName = getFullyQualifiedName(Ty);
2310+
std::string FullName = getFullyQualifiedName(Ty, getScopeSeparator());
23002311

23012312
UnionRecord UR(FieldCount, CO, FieldTI, SizeInBytes, FullName,
23022313
Ty->getIdentifier());

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)