@@ -279,21 +279,30 @@ static const DISubprogram *getQualifiedNameComponents(
279
279
}
280
280
281
281
static std::string getQualifiedName (ArrayRef<StringRef> QualifiedNameComponents,
282
- StringRef TypeName) {
282
+ StringRef TypeName, StringRef Separator ) {
283
283
std::string FullyQualifiedName;
284
284
for (StringRef QualifiedNameComponent :
285
285
llvm::reverse (QualifiedNameComponents)) {
286
286
FullyQualifiedName.append (QualifiedNameComponent);
287
- FullyQualifiedName.append (" :: " );
287
+ FullyQualifiedName.append (Separator );
288
288
}
289
289
FullyQualifiedName.append (TypeName);
290
290
return FullyQualifiedName;
291
291
}
292
292
293
- static std::string getFullyQualifiedName (const DIScope *Scope, StringRef Name) {
293
+ static std::string getFullyQualifiedName (const DIScope *Scope, StringRef Name,
294
+ StringRef Separator) {
294
295
SmallVector<StringRef, 5 > QualifiedNameComponents;
295
296
getQualifiedNameComponents (Scope, QualifiedNameComponents);
296
- return getQualifiedName (QualifiedNameComponents, Name);
297
+ return getQualifiedName (QualifiedNameComponents, Name, Separator);
298
+ }
299
+
300
+ // Added for LDC: use `.` as scope separator for compile units with D language
301
+ // tag.
302
+ const char *CodeViewDebug::getScopeSeparator () const {
303
+ NamedMDNode *CUs = MMI->getModule ()->getNamedMetadata (" llvm.dbg.cu" );
304
+ const DICompileUnit *CU = cast<DICompileUnit>(*CUs->operands ().begin ());
305
+ return CU->getSourceLanguage () == dwarf::DW_LANG_D ? " ." : " ::" ;
297
306
}
298
307
299
308
struct CodeViewDebug ::TypeLoweringScope {
@@ -308,9 +317,10 @@ struct CodeViewDebug::TypeLoweringScope {
308
317
CodeViewDebug &CVD;
309
318
};
310
319
311
- static std::string getFullyQualifiedName (const DIScope *Ty) {
320
+ static std::string getFullyQualifiedName (const DIScope *Ty,
321
+ StringRef Separator) {
312
322
const DIScope *Scope = Ty->getScope ().resolve ();
313
- return getFullyQualifiedName (Scope, getPrettyScopeName (Ty));
323
+ return getFullyQualifiedName (Scope, getPrettyScopeName (Ty), Separator );
314
324
}
315
325
316
326
TypeIndex CodeViewDebug::getScopeIndex (const DIScope *Scope) {
@@ -326,7 +336,7 @@ TypeIndex CodeViewDebug::getScopeIndex(const DIScope *Scope) {
326
336
return I->second ;
327
337
328
338
// Build the fully qualified name of the scope.
329
- std::string ScopeName = getFullyQualifiedName (Scope);
339
+ std::string ScopeName = getFullyQualifiedName (Scope, getScopeSeparator () );
330
340
StringIdRecord SID (TypeIndex (), ScopeName);
331
341
auto TI = TypeTable.writeLeafType (SID);
332
342
return recordTypeIndexForDINode (Scope, TI);
@@ -973,8 +983,8 @@ void CodeViewDebug::emitDebugInfoForFunction(const Function *GV,
973
983
// If we have a display name, build the fully qualified name by walking the
974
984
// chain of scopes.
975
985
if (!SP->getName ().empty ())
976
- FuncName =
977
- getFullyQualifiedName (SP-> getScope (). resolve (), SP-> getName ());
986
+ FuncName = getFullyQualifiedName (SP-> getScope (). resolve (), SP-> getName (),
987
+ getScopeSeparator ());
978
988
979
989
// If our DISubprogram name is empty, use the mangled name.
980
990
if (FuncName.empty ())
@@ -1412,8 +1422,8 @@ void CodeViewDebug::addToUDTs(const DIType *Ty) {
1412
1422
const DISubprogram *ClosestSubprogram = getQualifiedNameComponents (
1413
1423
Ty->getScope ().resolve (), QualifiedNameComponents);
1414
1424
1415
- std::string FullyQualifiedName =
1416
- getQualifiedName ( QualifiedNameComponents, getPrettyScopeName (Ty));
1425
+ std::string FullyQualifiedName = getQualifiedName (
1426
+ QualifiedNameComponents, getPrettyScopeName (Ty), getScopeSeparator ( ));
1417
1427
1418
1428
if (ClosestSubprogram == nullptr ) {
1419
1429
GlobalUDTs.emplace_back (std::move (FullyQualifiedName), Ty);
@@ -2013,7 +2023,7 @@ TypeIndex CodeViewDebug::lowerTypeEnum(const DICompositeType *Ty) {
2013
2023
FTI = TypeTable.insertRecord (ContinuationBuilder);
2014
2024
}
2015
2025
2016
- std::string FullName = getFullyQualifiedName (Ty);
2026
+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
2017
2027
2018
2028
EnumRecord ER (EnumeratorCount, CO, FTI, FullName, Ty->getIdentifier (),
2019
2029
getTypeIndex (Ty->getBaseType ()));
@@ -2164,7 +2174,7 @@ TypeIndex CodeViewDebug::lowerTypeClass(const DICompositeType *Ty) {
2164
2174
TypeRecordKind Kind = getRecordKind (Ty);
2165
2175
ClassOptions CO =
2166
2176
ClassOptions::ForwardReference | getCommonClassOptions (Ty);
2167
- std::string FullName = getFullyQualifiedName (Ty);
2177
+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
2168
2178
ClassRecord CR (Kind, 0 , CO, TypeIndex (), TypeIndex (), TypeIndex (), 0 ,
2169
2179
FullName, Ty->getIdentifier ());
2170
2180
TypeIndex FwdDeclTI = TypeTable.writeLeafType (CR);
@@ -2187,7 +2197,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeClass(const DICompositeType *Ty) {
2187
2197
if (ContainsNestedClass)
2188
2198
CO |= ClassOptions::ContainsNestedClass;
2189
2199
2190
- std::string FullName = getFullyQualifiedName (Ty);
2200
+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
2191
2201
2192
2202
uint64_t SizeInBytes = Ty->getSizeInBits () / 8 ;
2193
2203
@@ -2209,7 +2219,7 @@ TypeIndex CodeViewDebug::lowerTypeUnion(const DICompositeType *Ty) {
2209
2219
2210
2220
ClassOptions CO =
2211
2221
ClassOptions::ForwardReference | getCommonClassOptions (Ty);
2212
- std::string FullName = getFullyQualifiedName (Ty);
2222
+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
2213
2223
UnionRecord UR (0 , CO, TypeIndex (), 0 , FullName, Ty->getIdentifier ());
2214
2224
TypeIndex FwdDeclTI = TypeTable.writeLeafType (UR);
2215
2225
if (!Ty->isForwardDecl ())
@@ -2229,7 +2239,7 @@ TypeIndex CodeViewDebug::lowerCompleteTypeUnion(const DICompositeType *Ty) {
2229
2239
CO |= ClassOptions::ContainsNestedClass;
2230
2240
2231
2241
uint64_t SizeInBytes = Ty->getSizeInBits () / 8 ;
2232
- std::string FullName = getFullyQualifiedName (Ty);
2242
+ std::string FullName = getFullyQualifiedName (Ty, getScopeSeparator () );
2233
2243
2234
2244
UnionRecord UR (FieldCount, CO, FieldTI, SizeInBytes, FullName,
2235
2245
Ty->getIdentifier ());
0 commit comments