@@ -3495,14 +3495,15 @@ llvm::DISubprogram *CGDebugInfo::getObjCMethodDeclaration(
3495
3495
if (!D || DebugKind <= codegenoptions::DebugLineTablesOnly)
3496
3496
return nullptr ;
3497
3497
3498
- if (CGM.getCodeGenOpts ().DwarfVersion < 5 )
3498
+ const auto *OMD = dyn_cast<ObjCMethodDecl>(D);
3499
+ if (!OMD)
3500
+ return nullptr ;
3501
+
3502
+ if (CGM.getCodeGenOpts ().DwarfVersion < 5 && !OMD->isDirectMethod ())
3499
3503
return nullptr ;
3500
3504
3501
3505
// Starting with DWARF V5 method declarations are emitted as children of
3502
3506
// the interface type.
3503
- const auto *OMD = dyn_cast<ObjCMethodDecl>(D);
3504
- if (!OMD)
3505
- return nullptr ;
3506
3507
auto *ID = dyn_cast_or_null<ObjCInterfaceDecl>(D->getDeclContext ());
3507
3508
if (!ID)
3508
3509
ID = OMD->getClassInterface ();
@@ -3517,7 +3518,7 @@ llvm::DISubprogram *CGDebugInfo::getObjCMethodDeclaration(
3517
3518
InterfaceType, getObjCMethodName (OMD), StringRef (),
3518
3519
InterfaceType->getFile (), LineNo, FnType, LineNo, Flags, SPFlags);
3519
3520
DBuilder.finalizeSubprogram (FD);
3520
- ObjCMethodCache[ID].push_back (FD );
3521
+ ObjCMethodCache[ID].push_back ({FD, OMD-> isDirectMethod ()} );
3521
3522
return FD;
3522
3523
}
3523
3524
@@ -4713,27 +4714,28 @@ void CGDebugInfo::finalize() {
4713
4714
DBuilder.replaceTemporary (llvm::TempDIType (E.Decl ), Ty);
4714
4715
}
4715
4716
4716
- if (CGM.getCodeGenOpts ().DwarfVersion >= 5 ) {
4717
- // Add methods to interface.
4718
- for (const auto &P : ObjCMethodCache) {
4719
- if (P.second .empty ())
4720
- continue ;
4717
+ // Add methods to interface.
4718
+ for (const auto &P : ObjCMethodCache) {
4719
+ if (P.second .empty ())
4720
+ continue ;
4721
4721
4722
- QualType QTy (P.first ->getTypeForDecl (), 0 );
4723
- auto It = TypeCache.find (QTy.getAsOpaquePtr ());
4724
- assert (It != TypeCache.end ());
4722
+ QualType QTy (P.first ->getTypeForDecl (), 0 );
4723
+ auto It = TypeCache.find (QTy.getAsOpaquePtr ());
4724
+ assert (It != TypeCache.end ());
4725
4725
4726
- llvm::DICompositeType *InterfaceDecl =
4727
- cast<llvm::DICompositeType>(It->second );
4726
+ llvm::DICompositeType *InterfaceDecl =
4727
+ cast<llvm::DICompositeType>(It->second );
4728
4728
4729
- SmallVector<llvm::Metadata *, 16 > EltTys;
4730
- auto CurrenetElts = InterfaceDecl->getElements ();
4731
- EltTys.append (CurrenetElts.begin (), CurrenetElts.end ());
4732
- for (auto &MD : P.second )
4733
- EltTys.push_back (MD);
4734
- llvm::DINodeArray Elements = DBuilder.getOrCreateArray (EltTys);
4735
- DBuilder.replaceArrays (InterfaceDecl, Elements);
4736
- }
4729
+ auto CurElts = InterfaceDecl->getElements ();
4730
+ SmallVector<llvm::Metadata *, 16 > EltTys (CurElts.begin (), CurElts.end ());
4731
+
4732
+ // For DWARF v4 or earlier, only add objc_direct methods.
4733
+ for (auto &SubprogramDirect : P.second )
4734
+ if (CGM.getCodeGenOpts ().DwarfVersion >= 5 || SubprogramDirect.getInt ())
4735
+ EltTys.push_back (SubprogramDirect.getPointer ());
4736
+
4737
+ llvm::DINodeArray Elements = DBuilder.getOrCreateArray (EltTys);
4738
+ DBuilder.replaceArrays (InterfaceDecl, Elements);
4737
4739
}
4738
4740
4739
4741
for (const auto &P : ReplaceMap) {
0 commit comments