@@ -252,21 +252,30 @@ static const DISubprogram *getQualifiedNameComponents(
252252}
253253
254254static std::string getQualifiedName (ArrayRef<StringRef> QualifiedNameComponents,
255- StringRef TypeName) {
255+ StringRef TypeName, StringRef Separator ) {
256256 std::string FullyQualifiedName;
257257 for (StringRef QualifiedNameComponent :
258258 llvm::reverse (QualifiedNameComponents)) {
259259 FullyQualifiedName.append (QualifiedNameComponent);
260- FullyQualifiedName.append (" :: " );
260+ FullyQualifiedName.append (Separator );
261261 }
262262 FullyQualifiedName.append (TypeName);
263263 return FullyQualifiedName;
264264}
265265
266- static std::string getFullyQualifiedName (const DIScope *Scope, StringRef Name) {
266+ static std::string getFullyQualifiedName (const DIScope *Scope, StringRef Name,
267+ StringRef Separator) {
267268 SmallVector<StringRef, 5 > QualifiedNameComponents;
268269 getQualifiedNameComponents (Scope, QualifiedNameComponents);
269- return getQualifiedName (QualifiedNameComponents, Name);
270+ return getQualifiedName (QualifiedNameComponents, Name, Separator);
271+ }
272+
273+ // Added for LDC: use `.` as scope separator for compile units with D language
274+ // tag.
275+ const char *CodeViewDebug::getScopeSeparator () const {
276+ NamedMDNode *CUs = MMI->getModule ()->getNamedMetadata (" llvm.dbg.cu" );
277+ const DICompileUnit *CU = cast<DICompileUnit>(*CUs->operands ().begin ());
278+ return CU->getSourceLanguage () == dwarf::DW_LANG_D ? " ." : " ::" ;
270279}
271280
272281struct CodeViewDebug ::TypeLoweringScope {
@@ -281,9 +290,10 @@ struct CodeViewDebug::TypeLoweringScope {
281290 CodeViewDebug &CVD;
282291};
283292
284- static std::string getFullyQualifiedName (const DIScope *Ty) {
293+ static std::string getFullyQualifiedName (const DIScope *Ty,
294+ StringRef Separator) {
285295 const DIScope *Scope = Ty->getScope ().resolve ();
286- return getFullyQualifiedName (Scope, getPrettyScopeName (Ty));
296+ return getFullyQualifiedName (Scope, getPrettyScopeName (Ty), Separator );
287297}
288298
289299TypeIndex CodeViewDebug::getScopeIndex (const DIScope *Scope) {
@@ -299,7 +309,7 @@ TypeIndex CodeViewDebug::getScopeIndex(const DIScope *Scope) {
299309 return I->second ;
300310
301311 // Build the fully qualified name of the scope.
302- std::string ScopeName = getFullyQualifiedName (Scope);
312+ std::string ScopeName = getFullyQualifiedName (Scope, getScopeSeparator () );
303313 StringIdRecord SID (TypeIndex (), ScopeName);
304314 auto TI = TypeTable.writeLeafType (SID);
305315 return recordTypeIndexForDINode (Scope, TI);
@@ -912,8 +922,8 @@ void CodeViewDebug::emitDebugInfoForFunction(const Function *GV,
912922 // If we have a display name, build the fully qualified name by walking the
913923 // chain of scopes.
914924 if (!SP->getName ().empty ())
915- FuncName =
916- getFullyQualifiedName (SP-> getScope (). resolve (), SP-> getName ());
925+ FuncName = getFullyQualifiedName (SP-> getScope (). resolve (), SP-> getName (),
926+ getScopeSeparator ());
917927
918928 // If our DISubprogram name is empty, use the mangled name.
919929 if (FuncName.empty ())
@@ -1301,8 +1311,8 @@ void CodeViewDebug::addToUDTs(const DIType *Ty) {
13011311 const DISubprogram *ClosestSubprogram = getQualifiedNameComponents (
13021312 Ty->getScope ().resolve (), QualifiedNameComponents);
13031313
1304- std::string FullyQualifiedName =
1305- getQualifiedName ( QualifiedNameComponents, getPrettyScopeName (Ty));
1314+ std::string FullyQualifiedName = getQualifiedName (
1315+ QualifiedNameComponents, getPrettyScopeName (Ty), getScopeSeparator ( ));
13061316
13071317 if (ClosestSubprogram == nullptr ) {
13081318 GlobalUDTs.emplace_back (std::move (FullyQualifiedName), Ty);
@@ -1881,7 +1891,7 @@ TypeIndex CodeViewDebug::lowerTypeEnum(const DICompositeType *Ty) {
18811891 FTI = TypeTable.insertRecord (ContinuationBuilder);
18821892 }
18831893
1884- std::string FullName = getFullyQualifiedName (Ty);
1894+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
18851895
18861896 EnumRecord ER (EnumeratorCount, CO, FTI, FullName, Ty->getIdentifier (),
18871897 getTypeIndex (Ty->getBaseType ()));
@@ -2031,7 +2041,7 @@ TypeIndex CodeViewDebug::lowerTypeClass(const DICompositeType *Ty) {
20312041 TypeRecordKind Kind = getRecordKind (Ty);
20322042 ClassOptions CO =
20332043 ClassOptions::ForwardReference | getCommonClassOptions (Ty);
2034- std::string FullName = getFullyQualifiedName (Ty);
2044+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
20352045 ClassRecord CR (Kind, 0 , CO, TypeIndex (), TypeIndex (), TypeIndex (), 0 ,
20362046 FullName, Ty->getIdentifier ());
20372047 TypeIndex FwdDeclTI = TypeTable.writeLeafType (CR);
@@ -2054,7 +2064,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeClass(const DICompositeType *Ty) {
20542064 if (ContainsNestedClass)
20552065 CO |= ClassOptions::ContainsNestedClass;
20562066
2057- std::string FullName = getFullyQualifiedName (Ty);
2067+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
20582068
20592069 uint64_t SizeInBytes = Ty->getSizeInBits () / 8 ;
20602070
@@ -2076,7 +2086,7 @@ TypeIndex CodeViewDebug::lowerTypeUnion(const DICompositeType *Ty) {
20762086
20772087 ClassOptions CO =
20782088 ClassOptions::ForwardReference | getCommonClassOptions (Ty);
2079- std::string FullName = getFullyQualifiedName (Ty);
2089+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
20802090 UnionRecord UR (0 , CO, TypeIndex (), 0 , FullName, Ty->getIdentifier ());
20812091 TypeIndex FwdDeclTI = TypeTable.writeLeafType (UR);
20822092 if (!Ty->isForwardDecl ())
@@ -2096,7 +2106,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeUnion(const DICompositeType *Ty) {
20962106 CO |= ClassOptions::ContainsNestedClass;
20972107
20982108 uint64_t SizeInBytes = Ty->getSizeInBits () / 8 ;
2099- std::string FullName = getFullyQualifiedName (Ty);
2109+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
21002110
21012111 UnionRecord UR (FieldCount, CO, FieldTI, SizeInBytes, FullName,
21022112 Ty->getIdentifier ());
0 commit comments