@@ -301,21 +301,30 @@ static const DISubprogram *getQualifiedNameComponents(
301301}
302302
303303static std::string getQualifiedName (ArrayRef<StringRef> QualifiedNameComponents,
304- StringRef TypeName) {
304+ StringRef TypeName, StringRef Separator ) {
305305 std::string FullyQualifiedName;
306306 for (StringRef QualifiedNameComponent :
307307 llvm::reverse (QualifiedNameComponents)) {
308308 FullyQualifiedName.append (QualifiedNameComponent);
309- FullyQualifiedName.append (" :: " );
309+ FullyQualifiedName.append (Separator );
310310 }
311311 FullyQualifiedName.append (TypeName);
312312 return FullyQualifiedName;
313313}
314314
315- static std::string getFullyQualifiedName (const DIScope *Scope, StringRef Name) {
315+ static std::string getFullyQualifiedName (const DIScope *Scope, StringRef Name,
316+ StringRef Separator) {
316317 SmallVector<StringRef, 5 > QualifiedNameComponents;
317318 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 ? " ." : " ::" ;
319328}
320329
321330struct CodeViewDebug ::TypeLoweringScope {
@@ -330,9 +339,10 @@ struct CodeViewDebug::TypeLoweringScope {
330339 CodeViewDebug &CVD;
331340};
332341
333- static std::string getFullyQualifiedName (const DIScope *Ty) {
342+ static std::string getFullyQualifiedName (const DIScope *Ty,
343+ StringRef Separator) {
334344 const DIScope *Scope = Ty->getScope ();
335- return getFullyQualifiedName (Scope, getPrettyScopeName (Ty));
345+ return getFullyQualifiedName (Scope, getPrettyScopeName (Ty), Separator );
336346}
337347
338348TypeIndex CodeViewDebug::getScopeIndex (const DIScope *Scope) {
@@ -348,7 +358,7 @@ TypeIndex CodeViewDebug::getScopeIndex(const DIScope *Scope) {
348358 return I->second ;
349359
350360 // Build the fully qualified name of the scope.
351- std::string ScopeName = getFullyQualifiedName (Scope);
361+ std::string ScopeName = getFullyQualifiedName (Scope, getScopeSeparator () );
352362 StringIdRecord SID (TypeIndex (), ScopeName);
353363 auto TI = TypeTable.writeLeafType (SID);
354364 return recordTypeIndexForDINode (Scope, TI);
@@ -1029,7 +1039,8 @@ void CodeViewDebug::emitDebugInfoForFunction(const Function *GV,
10291039 // If we have a display name, build the fully qualified name by walking the
10301040 // chain of scopes.
10311041 if (!SP->getName ().empty ())
1032- FuncName = getFullyQualifiedName (SP->getScope (), SP->getName ());
1042+ FuncName = getFullyQualifiedName (SP->getScope (), SP->getName (),
1043+ getScopeSeparator ());
10331044
10341045 // If our DISubprogram name is empty, use the mangled name.
10351046 if (FuncName.empty ())
@@ -1495,8 +1506,8 @@ void CodeViewDebug::addToUDTs(const DIType *Ty) {
14951506 const DISubprogram *ClosestSubprogram =
14961507 getQualifiedNameComponents (Ty->getScope (), QualifiedNameComponents);
14971508
1498- std::string FullyQualifiedName =
1499- getQualifiedName ( QualifiedNameComponents, getPrettyScopeName (Ty));
1509+ std::string FullyQualifiedName = getQualifiedName (
1510+ QualifiedNameComponents, getPrettyScopeName (Ty), getScopeSeparator ( ));
15001511
15011512 if (ClosestSubprogram == nullptr ) {
15021513 GlobalUDTs.emplace_back (std::move (FullyQualifiedName), Ty);
@@ -2095,7 +2106,7 @@ TypeIndex CodeViewDebug::lowerTypeEnum(const DICompositeType *Ty) {
20952106 FTI = TypeTable.insertRecord (ContinuationBuilder);
20962107 }
20972108
2098- std::string FullName = getFullyQualifiedName (Ty);
2109+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
20992110
21002111 EnumRecord ER (EnumeratorCount, CO, FTI, FullName, Ty->getIdentifier (),
21012112 getTypeIndex (Ty->getBaseType ()));
@@ -2246,7 +2257,7 @@ TypeIndex CodeViewDebug::lowerTypeClass(const DICompositeType *Ty) {
22462257 TypeRecordKind Kind = getRecordKind (Ty);
22472258 ClassOptions CO =
22482259 ClassOptions::ForwardReference | getCommonClassOptions (Ty);
2249- std::string FullName = getFullyQualifiedName (Ty);
2260+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
22502261 ClassRecord CR (Kind, 0 , CO, TypeIndex (), TypeIndex (), TypeIndex (), 0 ,
22512262 FullName, Ty->getIdentifier ());
22522263 TypeIndex FwdDeclTI = TypeTable.writeLeafType (CR);
@@ -2277,7 +2288,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeClass(const DICompositeType *Ty) {
22772288 if (isNonTrivial (Ty))
22782289 CO |= ClassOptions::HasConstructorOrDestructor;
22792290
2280- std::string FullName = getFullyQualifiedName (Ty);
2291+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
22812292
22822293 uint64_t SizeInBytes = Ty->getSizeInBits () / 8 ;
22832294
@@ -2299,7 +2310,7 @@ TypeIndex CodeViewDebug::lowerTypeUnion(const DICompositeType *Ty) {
22992310
23002311 ClassOptions CO =
23012312 ClassOptions::ForwardReference | getCommonClassOptions (Ty);
2302- std::string FullName = getFullyQualifiedName (Ty);
2313+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
23032314 UnionRecord UR (0 , CO, TypeIndex (), 0 , FullName, Ty->getIdentifier ());
23042315 TypeIndex FwdDeclTI = TypeTable.writeLeafType (UR);
23052316 if (!Ty->isForwardDecl ())
@@ -2319,7 +2330,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeUnion(const DICompositeType *Ty) {
23192330 CO |= ClassOptions::ContainsNestedClass;
23202331
23212332 uint64_t SizeInBytes = Ty->getSizeInBits () / 8 ;
2322- std::string FullName = getFullyQualifiedName (Ty);
2333+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
23232334
23242335 UnionRecord UR (FieldCount, CO, FieldTI, SizeInBytes, FullName,
23252336 Ty->getIdentifier ());
0 commit comments