@@ -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 ())
@@ -1499,8 +1510,8 @@ void CodeViewDebug::addToUDTs(const DIType *Ty) {
14991510 const DISubprogram *ClosestSubprogram =
15001511 getQualifiedNameComponents (Ty->getScope (), QualifiedNameComponents);
15011512
1502- std::string FullyQualifiedName =
1503- getQualifiedName ( QualifiedNameComponents, getPrettyScopeName (Ty));
1513+ std::string FullyQualifiedName = getQualifiedName (
1514+ QualifiedNameComponents, getPrettyScopeName (Ty), getScopeSeparator ( ));
15041515
15051516 if (ClosestSubprogram == nullptr ) {
15061517 GlobalUDTs.emplace_back (std::move (FullyQualifiedName), Ty);
@@ -2099,7 +2110,7 @@ TypeIndex CodeViewDebug::lowerTypeEnum(const DICompositeType *Ty) {
20992110 FTI = TypeTable.insertRecord (ContinuationBuilder);
21002111 }
21012112
2102- std::string FullName = getFullyQualifiedName (Ty);
2113+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
21032114
21042115 EnumRecord ER (EnumeratorCount, CO, FTI, FullName, Ty->getIdentifier (),
21052116 getTypeIndex (Ty->getBaseType ()));
@@ -2250,7 +2261,7 @@ TypeIndex CodeViewDebug::lowerTypeClass(const DICompositeType *Ty) {
22502261 TypeRecordKind Kind = getRecordKind (Ty);
22512262 ClassOptions CO =
22522263 ClassOptions::ForwardReference | getCommonClassOptions (Ty);
2253- std::string FullName = getFullyQualifiedName (Ty);
2264+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
22542265 ClassRecord CR (Kind, 0 , CO, TypeIndex (), TypeIndex (), TypeIndex (), 0 ,
22552266 FullName, Ty->getIdentifier ());
22562267 TypeIndex FwdDeclTI = TypeTable.writeLeafType (CR);
@@ -2281,7 +2292,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeClass(const DICompositeType *Ty) {
22812292 if (isNonTrivial (Ty))
22822293 CO |= ClassOptions::HasConstructorOrDestructor;
22832294
2284- std::string FullName = getFullyQualifiedName (Ty);
2295+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
22852296
22862297 uint64_t SizeInBytes = Ty->getSizeInBits () / 8 ;
22872298
@@ -2303,7 +2314,7 @@ TypeIndex CodeViewDebug::lowerTypeUnion(const DICompositeType *Ty) {
23032314
23042315 ClassOptions CO =
23052316 ClassOptions::ForwardReference | getCommonClassOptions (Ty);
2306- std::string FullName = getFullyQualifiedName (Ty);
2317+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
23072318 UnionRecord UR (0 , CO, TypeIndex (), 0 , FullName, Ty->getIdentifier ());
23082319 TypeIndex FwdDeclTI = TypeTable.writeLeafType (UR);
23092320 if (!Ty->isForwardDecl ())
@@ -2323,7 +2334,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeUnion(const DICompositeType *Ty) {
23232334 CO |= ClassOptions::ContainsNestedClass;
23242335
23252336 uint64_t SizeInBytes = Ty->getSizeInBits () / 8 ;
2326- std::string FullName = getFullyQualifiedName (Ty);
2337+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
23272338
23282339 UnionRecord UR (FieldCount, CO, FieldTI, SizeInBytes, FullName,
23292340 Ty->getIdentifier ());
0 commit comments