Skip to content
This repository was archived by the owner on Dec 20, 2019. It is now read-only.

Commit 5c1d425

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 afa3920 commit 5c1d425

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

+26-16
Original file line numberDiff line numberDiff line change
@@ -279,21 +279,30 @@ static const DISubprogram *getQualifiedNameComponents(
279279
}
280280

281281
static std::string getQualifiedName(ArrayRef<StringRef> QualifiedNameComponents,
282-
StringRef TypeName) {
282+
StringRef TypeName, StringRef Separator) {
283283
std::string FullyQualifiedName;
284284
for (StringRef QualifiedNameComponent :
285285
llvm::reverse(QualifiedNameComponents)) {
286286
FullyQualifiedName.append(QualifiedNameComponent);
287-
FullyQualifiedName.append("::");
287+
FullyQualifiedName.append(Separator);
288288
}
289289
FullyQualifiedName.append(TypeName);
290290
return FullyQualifiedName;
291291
}
292292

293-
static std::string getFullyQualifiedName(const DIScope *Scope, StringRef Name) {
293+
static std::string getFullyQualifiedName(const DIScope *Scope, StringRef Name,
294+
StringRef Separator) {
294295
SmallVector<StringRef, 5> QualifiedNameComponents;
295296
getQualifiedNameComponents(Scope, QualifiedNameComponents);
296-
return getQualifiedName(QualifiedNameComponents, Name);
297+
return getQualifiedName(QualifiedNameComponents, Name, Separator);
298+
}
299+
300+
// Added for LDC: use `.` as scope separator for compile units with D language
301+
// tag.
302+
const char *CodeViewDebug::getScopeSeparator() const {
303+
NamedMDNode *CUs = MMI->getModule()->getNamedMetadata("llvm.dbg.cu");
304+
const DICompileUnit *CU = cast<DICompileUnit>(*CUs->operands().begin());
305+
return CU->getSourceLanguage() == dwarf::DW_LANG_D ? "." : "::";
297306
}
298307

299308
struct CodeViewDebug::TypeLoweringScope {
@@ -308,9 +317,10 @@ struct CodeViewDebug::TypeLoweringScope {
308317
CodeViewDebug &CVD;
309318
};
310319

311-
static std::string getFullyQualifiedName(const DIScope *Ty) {
320+
static std::string getFullyQualifiedName(const DIScope *Ty,
321+
StringRef Separator) {
312322
const DIScope *Scope = Ty->getScope().resolve();
313-
return getFullyQualifiedName(Scope, getPrettyScopeName(Ty));
323+
return getFullyQualifiedName(Scope, getPrettyScopeName(Ty), Separator);
314324
}
315325

316326
TypeIndex CodeViewDebug::getScopeIndex(const DIScope *Scope) {
@@ -326,7 +336,7 @@ TypeIndex CodeViewDebug::getScopeIndex(const DIScope *Scope) {
326336
return I->second;
327337

328338
// Build the fully qualified name of the scope.
329-
std::string ScopeName = getFullyQualifiedName(Scope);
339+
std::string ScopeName = getFullyQualifiedName(Scope, getScopeSeparator());
330340
StringIdRecord SID(TypeIndex(), ScopeName);
331341
auto TI = TypeTable.writeLeafType(SID);
332342
return recordTypeIndexForDINode(Scope, TI);
@@ -973,8 +983,8 @@ void CodeViewDebug::emitDebugInfoForFunction(const Function *GV,
973983
// If we have a display name, build the fully qualified name by walking the
974984
// chain of scopes.
975985
if (!SP->getName().empty())
976-
FuncName =
977-
getFullyQualifiedName(SP->getScope().resolve(), SP->getName());
986+
FuncName = getFullyQualifiedName(SP->getScope().resolve(), SP->getName(),
987+
getScopeSeparator());
978988

979989
// If our DISubprogram name is empty, use the mangled name.
980990
if (FuncName.empty())
@@ -1412,8 +1422,8 @@ void CodeViewDebug::addToUDTs(const DIType *Ty) {
14121422
const DISubprogram *ClosestSubprogram = getQualifiedNameComponents(
14131423
Ty->getScope().resolve(), QualifiedNameComponents);
14141424

1415-
std::string FullyQualifiedName =
1416-
getQualifiedName(QualifiedNameComponents, getPrettyScopeName(Ty));
1425+
std::string FullyQualifiedName = getQualifiedName(
1426+
QualifiedNameComponents, getPrettyScopeName(Ty), getScopeSeparator());
14171427

14181428
if (ClosestSubprogram == nullptr) {
14191429
GlobalUDTs.emplace_back(std::move(FullyQualifiedName), Ty);
@@ -2013,7 +2023,7 @@ TypeIndex CodeViewDebug::lowerTypeEnum(const DICompositeType *Ty) {
20132023
FTI = TypeTable.insertRecord(ContinuationBuilder);
20142024
}
20152025

2016-
std::string FullName = getFullyQualifiedName(Ty);
2026+
std::string FullName = getFullyQualifiedName(Ty, getScopeSeparator());
20172027

20182028
EnumRecord ER(EnumeratorCount, CO, FTI, FullName, Ty->getIdentifier(),
20192029
getTypeIndex(Ty->getBaseType()));
@@ -2164,7 +2174,7 @@ TypeIndex CodeViewDebug::lowerTypeClass(const DICompositeType *Ty) {
21642174
TypeRecordKind Kind = getRecordKind(Ty);
21652175
ClassOptions CO =
21662176
ClassOptions::ForwardReference | getCommonClassOptions(Ty);
2167-
std::string FullName = getFullyQualifiedName(Ty);
2177+
std::string FullName = getFullyQualifiedName(Ty, getScopeSeparator());
21682178
ClassRecord CR(Kind, 0, CO, TypeIndex(), TypeIndex(), TypeIndex(), 0,
21692179
FullName, Ty->getIdentifier());
21702180
TypeIndex FwdDeclTI = TypeTable.writeLeafType(CR);
@@ -2187,7 +2197,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeClass(const DICompositeType *Ty) {
21872197
if (ContainsNestedClass)
21882198
CO |= ClassOptions::ContainsNestedClass;
21892199

2190-
std::string FullName = getFullyQualifiedName(Ty);
2200+
std::string FullName = getFullyQualifiedName(Ty, getScopeSeparator());
21912201

21922202
uint64_t SizeInBytes = Ty->getSizeInBits() / 8;
21932203

@@ -2209,7 +2219,7 @@ TypeIndex CodeViewDebug::lowerTypeUnion(const DICompositeType *Ty) {
22092219

22102220
ClassOptions CO =
22112221
ClassOptions::ForwardReference | getCommonClassOptions(Ty);
2212-
std::string FullName = getFullyQualifiedName(Ty);
2222+
std::string FullName = getFullyQualifiedName(Ty, getScopeSeparator());
22132223
UnionRecord UR(0, CO, TypeIndex(), 0, FullName, Ty->getIdentifier());
22142224
TypeIndex FwdDeclTI = TypeTable.writeLeafType(UR);
22152225
if (!Ty->isForwardDecl())
@@ -2229,7 +2239,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeUnion(const DICompositeType *Ty) {
22292239
CO |= ClassOptions::ContainsNestedClass;
22302240

22312241
uint64_t SizeInBytes = Ty->getSizeInBits() / 8;
2232-
std::string FullName = getFullyQualifiedName(Ty);
2242+
std::string FullName = getFullyQualifiedName(Ty, getScopeSeparator());
22332243

22342244
UnionRecord UR(FieldCount, CO, FieldTI, SizeInBytes, FullName,
22352245
Ty->getIdentifier());

lib/CodeGen/AsmPrinter/CodeViewDebug.h

+3
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase {
285285
LocalUDTs.clear();
286286
}
287287

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

0 commit comments

Comments
 (0)