@@ -252,21 +252,30 @@ static const DISubprogram *getQualifiedNameComponents(
252
252
}
253
253
254
254
static std::string getQualifiedName (ArrayRef<StringRef> QualifiedNameComponents,
255
- StringRef TypeName) {
255
+ StringRef TypeName, StringRef Separator ) {
256
256
std::string FullyQualifiedName;
257
257
for (StringRef QualifiedNameComponent :
258
258
llvm::reverse (QualifiedNameComponents)) {
259
259
FullyQualifiedName.append (QualifiedNameComponent);
260
- FullyQualifiedName.append (" :: " );
260
+ FullyQualifiedName.append (Separator );
261
261
}
262
262
FullyQualifiedName.append (TypeName);
263
263
return FullyQualifiedName;
264
264
}
265
265
266
- static std::string getFullyQualifiedName (const DIScope *Scope, StringRef Name) {
266
+ static std::string getFullyQualifiedName (const DIScope *Scope, StringRef Name,
267
+ StringRef Separator) {
267
268
SmallVector<StringRef, 5 > QualifiedNameComponents;
268
269
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 ? " ." : " ::" ;
270
279
}
271
280
272
281
struct CodeViewDebug ::TypeLoweringScope {
@@ -281,9 +290,10 @@ struct CodeViewDebug::TypeLoweringScope {
281
290
CodeViewDebug &CVD;
282
291
};
283
292
284
- static std::string getFullyQualifiedName (const DIScope *Ty) {
293
+ static std::string getFullyQualifiedName (const DIScope *Ty,
294
+ StringRef Separator) {
285
295
const DIScope *Scope = Ty->getScope ().resolve ();
286
- return getFullyQualifiedName (Scope, getPrettyScopeName (Ty));
296
+ return getFullyQualifiedName (Scope, getPrettyScopeName (Ty), Separator );
287
297
}
288
298
289
299
TypeIndex CodeViewDebug::getScopeIndex (const DIScope *Scope) {
@@ -299,7 +309,7 @@ TypeIndex CodeViewDebug::getScopeIndex(const DIScope *Scope) {
299
309
return I->second ;
300
310
301
311
// Build the fully qualified name of the scope.
302
- std::string ScopeName = getFullyQualifiedName (Scope);
312
+ std::string ScopeName = getFullyQualifiedName (Scope, getScopeSeparator () );
303
313
StringIdRecord SID (TypeIndex (), ScopeName);
304
314
auto TI = TypeTable.writeLeafType (SID);
305
315
return recordTypeIndexForDINode (Scope, TI);
@@ -912,8 +922,8 @@ void CodeViewDebug::emitDebugInfoForFunction(const Function *GV,
912
922
// If we have a display name, build the fully qualified name by walking the
913
923
// chain of scopes.
914
924
if (!SP->getName ().empty ())
915
- FuncName =
916
- getFullyQualifiedName (SP-> getScope (). resolve (), SP-> getName ());
925
+ FuncName = getFullyQualifiedName (SP-> getScope (). resolve (), SP-> getName (),
926
+ getScopeSeparator ());
917
927
918
928
// If our DISubprogram name is empty, use the mangled name.
919
929
if (FuncName.empty ())
@@ -1301,8 +1311,8 @@ void CodeViewDebug::addToUDTs(const DIType *Ty) {
1301
1311
const DISubprogram *ClosestSubprogram = getQualifiedNameComponents (
1302
1312
Ty->getScope ().resolve (), QualifiedNameComponents);
1303
1313
1304
- std::string FullyQualifiedName =
1305
- getQualifiedName ( QualifiedNameComponents, getPrettyScopeName (Ty));
1314
+ std::string FullyQualifiedName = getQualifiedName (
1315
+ QualifiedNameComponents, getPrettyScopeName (Ty), getScopeSeparator ( ));
1306
1316
1307
1317
if (ClosestSubprogram == nullptr ) {
1308
1318
GlobalUDTs.emplace_back (std::move (FullyQualifiedName), Ty);
@@ -1881,7 +1891,7 @@ TypeIndex CodeViewDebug::lowerTypeEnum(const DICompositeType *Ty) {
1881
1891
FTI = TypeTable.insertRecord (ContinuationBuilder);
1882
1892
}
1883
1893
1884
- std::string FullName = getFullyQualifiedName (Ty);
1894
+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
1885
1895
1886
1896
EnumRecord ER (EnumeratorCount, CO, FTI, FullName, Ty->getIdentifier (),
1887
1897
getTypeIndex (Ty->getBaseType ()));
@@ -2031,7 +2041,7 @@ TypeIndex CodeViewDebug::lowerTypeClass(const DICompositeType *Ty) {
2031
2041
TypeRecordKind Kind = getRecordKind (Ty);
2032
2042
ClassOptions CO =
2033
2043
ClassOptions::ForwardReference | getCommonClassOptions (Ty);
2034
- std::string FullName = getFullyQualifiedName (Ty);
2044
+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
2035
2045
ClassRecord CR (Kind, 0 , CO, TypeIndex (), TypeIndex (), TypeIndex (), 0 ,
2036
2046
FullName, Ty->getIdentifier ());
2037
2047
TypeIndex FwdDeclTI = TypeTable.writeLeafType (CR);
@@ -2054,7 +2064,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeClass(const DICompositeType *Ty) {
2054
2064
if (ContainsNestedClass)
2055
2065
CO |= ClassOptions::ContainsNestedClass;
2056
2066
2057
- std::string FullName = getFullyQualifiedName (Ty);
2067
+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
2058
2068
2059
2069
uint64_t SizeInBytes = Ty->getSizeInBits () / 8 ;
2060
2070
@@ -2076,7 +2086,7 @@ TypeIndex CodeViewDebug::lowerTypeUnion(const DICompositeType *Ty) {
2076
2086
2077
2087
ClassOptions CO =
2078
2088
ClassOptions::ForwardReference | getCommonClassOptions (Ty);
2079
- std::string FullName = getFullyQualifiedName (Ty);
2089
+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
2080
2090
UnionRecord UR (0 , CO, TypeIndex (), 0 , FullName, Ty->getIdentifier ());
2081
2091
TypeIndex FwdDeclTI = TypeTable.writeLeafType (UR);
2082
2092
if (!Ty->isForwardDecl ())
@@ -2096,7 +2106,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeUnion(const DICompositeType *Ty) {
2096
2106
CO |= ClassOptions::ContainsNestedClass;
2097
2107
2098
2108
uint64_t SizeInBytes = Ty->getSizeInBits () / 8 ;
2099
- std::string FullName = getFullyQualifiedName (Ty);
2109
+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
2100
2110
2101
2111
UnionRecord UR (FieldCount, CO, FieldTI, SizeInBytes, FullName,
2102
2112
Ty->getIdentifier ());
0 commit comments