@@ -301,21 +301,30 @@ static const DISubprogram *getQualifiedNameComponents(
301
301
}
302
302
303
303
static std::string getQualifiedName (ArrayRef<StringRef> QualifiedNameComponents,
304
- StringRef TypeName) {
304
+ StringRef TypeName, StringRef Separator ) {
305
305
std::string FullyQualifiedName;
306
306
for (StringRef QualifiedNameComponent :
307
307
llvm::reverse (QualifiedNameComponents)) {
308
308
FullyQualifiedName.append (QualifiedNameComponent);
309
- FullyQualifiedName.append (" :: " );
309
+ FullyQualifiedName.append (Separator );
310
310
}
311
311
FullyQualifiedName.append (TypeName);
312
312
return FullyQualifiedName;
313
313
}
314
314
315
- static std::string getFullyQualifiedName (const DIScope *Scope, StringRef Name) {
315
+ static std::string getFullyQualifiedName (const DIScope *Scope, StringRef Name,
316
+ StringRef Separator) {
316
317
SmallVector<StringRef, 5 > QualifiedNameComponents;
317
318
getQualifiedNameComponents (Scope, QualifiedNameComponents);
318
- return getQualifiedName (QualifiedNameComponents, Name);
319
+ return getQualifiedName (QualifiedNameComponents, Name, Separator);
320
+ }
321
+
322
+ // Added for LDC: use `.` as scope separator for compile units with D language
323
+ // tag.
324
+ const char *CodeViewDebug::getScopeSeparator () const {
325
+ NamedMDNode *CUs = MMI->getModule ()->getNamedMetadata (" llvm.dbg.cu" );
326
+ const DICompileUnit *CU = cast<DICompileUnit>(*CUs->operands ().begin ());
327
+ return CU->getSourceLanguage () == dwarf::DW_LANG_D ? " ." : " ::" ;
319
328
}
320
329
321
330
struct CodeViewDebug ::TypeLoweringScope {
@@ -330,9 +339,10 @@ struct CodeViewDebug::TypeLoweringScope {
330
339
CodeViewDebug &CVD;
331
340
};
332
341
333
- static std::string getFullyQualifiedName (const DIScope *Ty) {
342
+ static std::string getFullyQualifiedName (const DIScope *Ty,
343
+ StringRef Separator) {
334
344
const DIScope *Scope = Ty->getScope ();
335
- return getFullyQualifiedName (Scope, getPrettyScopeName (Ty));
345
+ return getFullyQualifiedName (Scope, getPrettyScopeName (Ty), Separator );
336
346
}
337
347
338
348
TypeIndex CodeViewDebug::getScopeIndex (const DIScope *Scope) {
@@ -348,7 +358,7 @@ TypeIndex CodeViewDebug::getScopeIndex(const DIScope *Scope) {
348
358
return I->second ;
349
359
350
360
// Build the fully qualified name of the scope.
351
- std::string ScopeName = getFullyQualifiedName (Scope);
361
+ std::string ScopeName = getFullyQualifiedName (Scope, getScopeSeparator () );
352
362
StringIdRecord SID (TypeIndex (), ScopeName);
353
363
auto TI = TypeTable.writeLeafType (SID);
354
364
return recordTypeIndexForDINode (Scope, TI);
@@ -1029,7 +1039,8 @@ void CodeViewDebug::emitDebugInfoForFunction(const Function *GV,
1029
1039
// If we have a display name, build the fully qualified name by walking the
1030
1040
// chain of scopes.
1031
1041
if (!SP->getName ().empty ())
1032
- FuncName = getFullyQualifiedName (SP->getScope (), SP->getName ());
1042
+ FuncName = getFullyQualifiedName (SP->getScope (), SP->getName (),
1043
+ getScopeSeparator ());
1033
1044
1034
1045
// If our DISubprogram name is empty, use the mangled name.
1035
1046
if (FuncName.empty ())
@@ -1499,8 +1510,8 @@ void CodeViewDebug::addToUDTs(const DIType *Ty) {
1499
1510
const DISubprogram *ClosestSubprogram =
1500
1511
getQualifiedNameComponents (Ty->getScope (), QualifiedNameComponents);
1501
1512
1502
- std::string FullyQualifiedName =
1503
- getQualifiedName ( QualifiedNameComponents, getPrettyScopeName (Ty));
1513
+ std::string FullyQualifiedName = getQualifiedName (
1514
+ QualifiedNameComponents, getPrettyScopeName (Ty), getScopeSeparator ( ));
1504
1515
1505
1516
if (ClosestSubprogram == nullptr ) {
1506
1517
GlobalUDTs.emplace_back (std::move (FullyQualifiedName), Ty);
@@ -2099,7 +2110,7 @@ TypeIndex CodeViewDebug::lowerTypeEnum(const DICompositeType *Ty) {
2099
2110
FTI = TypeTable.insertRecord (ContinuationBuilder);
2100
2111
}
2101
2112
2102
- std::string FullName = getFullyQualifiedName (Ty);
2113
+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
2103
2114
2104
2115
EnumRecord ER (EnumeratorCount, CO, FTI, FullName, Ty->getIdentifier (),
2105
2116
getTypeIndex (Ty->getBaseType ()));
@@ -2250,7 +2261,7 @@ TypeIndex CodeViewDebug::lowerTypeClass(const DICompositeType *Ty) {
2250
2261
TypeRecordKind Kind = getRecordKind (Ty);
2251
2262
ClassOptions CO =
2252
2263
ClassOptions::ForwardReference | getCommonClassOptions (Ty);
2253
- std::string FullName = getFullyQualifiedName (Ty);
2264
+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
2254
2265
ClassRecord CR (Kind, 0 , CO, TypeIndex (), TypeIndex (), TypeIndex (), 0 ,
2255
2266
FullName, Ty->getIdentifier ());
2256
2267
TypeIndex FwdDeclTI = TypeTable.writeLeafType (CR);
@@ -2281,7 +2292,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeClass(const DICompositeType *Ty) {
2281
2292
if (isNonTrivial (Ty))
2282
2293
CO |= ClassOptions::HasConstructorOrDestructor;
2283
2294
2284
- std::string FullName = getFullyQualifiedName (Ty);
2295
+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
2285
2296
2286
2297
uint64_t SizeInBytes = Ty->getSizeInBits () / 8 ;
2287
2298
@@ -2303,7 +2314,7 @@ TypeIndex CodeViewDebug::lowerTypeUnion(const DICompositeType *Ty) {
2303
2314
2304
2315
ClassOptions CO =
2305
2316
ClassOptions::ForwardReference | getCommonClassOptions (Ty);
2306
- std::string FullName = getFullyQualifiedName (Ty);
2317
+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
2307
2318
UnionRecord UR (0 , CO, TypeIndex (), 0 , FullName, Ty->getIdentifier ());
2308
2319
TypeIndex FwdDeclTI = TypeTable.writeLeafType (UR);
2309
2320
if (!Ty->isForwardDecl ())
@@ -2323,7 +2334,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeUnion(const DICompositeType *Ty) {
2323
2334
CO |= ClassOptions::ContainsNestedClass;
2324
2335
2325
2336
uint64_t SizeInBytes = Ty->getSizeInBits () / 8 ;
2326
- std::string FullName = getFullyQualifiedName (Ty);
2337
+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
2327
2338
2328
2339
UnionRecord UR (FieldCount, CO, FieldTI, SizeInBytes, FullName,
2329
2340
Ty->getIdentifier ());
0 commit comments