@@ -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 ())
@@ -1495,8 +1506,8 @@ void CodeViewDebug::addToUDTs(const DIType *Ty) {
1495
1506
const DISubprogram *ClosestSubprogram =
1496
1507
getQualifiedNameComponents (Ty->getScope (), QualifiedNameComponents);
1497
1508
1498
- std::string FullyQualifiedName =
1499
- getQualifiedName ( QualifiedNameComponents, getPrettyScopeName (Ty));
1509
+ std::string FullyQualifiedName = getQualifiedName (
1510
+ QualifiedNameComponents, getPrettyScopeName (Ty), getScopeSeparator ( ));
1500
1511
1501
1512
if (ClosestSubprogram == nullptr ) {
1502
1513
GlobalUDTs.emplace_back (std::move (FullyQualifiedName), Ty);
@@ -2095,7 +2106,7 @@ TypeIndex CodeViewDebug::lowerTypeEnum(const DICompositeType *Ty) {
2095
2106
FTI = TypeTable.insertRecord (ContinuationBuilder);
2096
2107
}
2097
2108
2098
- std::string FullName = getFullyQualifiedName (Ty);
2109
+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
2099
2110
2100
2111
EnumRecord ER (EnumeratorCount, CO, FTI, FullName, Ty->getIdentifier (),
2101
2112
getTypeIndex (Ty->getBaseType ()));
@@ -2246,7 +2257,7 @@ TypeIndex CodeViewDebug::lowerTypeClass(const DICompositeType *Ty) {
2246
2257
TypeRecordKind Kind = getRecordKind (Ty);
2247
2258
ClassOptions CO =
2248
2259
ClassOptions::ForwardReference | getCommonClassOptions (Ty);
2249
- std::string FullName = getFullyQualifiedName (Ty);
2260
+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
2250
2261
ClassRecord CR (Kind, 0 , CO, TypeIndex (), TypeIndex (), TypeIndex (), 0 ,
2251
2262
FullName, Ty->getIdentifier ());
2252
2263
TypeIndex FwdDeclTI = TypeTable.writeLeafType (CR);
@@ -2277,7 +2288,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeClass(const DICompositeType *Ty) {
2277
2288
if (isNonTrivial (Ty))
2278
2289
CO |= ClassOptions::HasConstructorOrDestructor;
2279
2290
2280
- std::string FullName = getFullyQualifiedName (Ty);
2291
+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
2281
2292
2282
2293
uint64_t SizeInBytes = Ty->getSizeInBits () / 8 ;
2283
2294
@@ -2299,7 +2310,7 @@ TypeIndex CodeViewDebug::lowerTypeUnion(const DICompositeType *Ty) {
2299
2310
2300
2311
ClassOptions CO =
2301
2312
ClassOptions::ForwardReference | getCommonClassOptions (Ty);
2302
- std::string FullName = getFullyQualifiedName (Ty);
2313
+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
2303
2314
UnionRecord UR (0 , CO, TypeIndex (), 0 , FullName, Ty->getIdentifier ());
2304
2315
TypeIndex FwdDeclTI = TypeTable.writeLeafType (UR);
2305
2316
if (!Ty->isForwardDecl ())
@@ -2319,7 +2330,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeUnion(const DICompositeType *Ty) {
2319
2330
CO |= ClassOptions::ContainsNestedClass;
2320
2331
2321
2332
uint64_t SizeInBytes = Ty->getSizeInBits () / 8 ;
2322
- std::string FullName = getFullyQualifiedName (Ty);
2333
+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
2323
2334
2324
2335
UnionRecord UR (FieldCount, CO, FieldTI, SizeInBytes, FullName,
2325
2336
Ty->getIdentifier ());
0 commit comments