@@ -3504,14 +3504,15 @@ llvm::DISubprogram *CGDebugInfo::getObjCMethodDeclaration(
3504
3504
if (!D || DebugKind <= codegenoptions::DebugLineTablesOnly)
3505
3505
return nullptr ;
3506
3506
3507
- if (CGM.getCodeGenOpts ().DwarfVersion < 5 )
3507
+ const auto *OMD = dyn_cast<ObjCMethodDecl>(D);
3508
+ if (!OMD)
3509
+ return nullptr ;
3510
+
3511
+ if (CGM.getCodeGenOpts ().DwarfVersion < 5 && !OMD->isDirectMethod ())
3508
3512
return nullptr ;
3509
3513
3510
3514
// Starting with DWARF V5 method declarations are emitted as children of
3511
3515
// the interface type.
3512
- const auto *OMD = dyn_cast<ObjCMethodDecl>(D);
3513
- if (!OMD)
3514
- return nullptr ;
3515
3516
auto *ID = dyn_cast_or_null<ObjCInterfaceDecl>(D->getDeclContext ());
3516
3517
if (!ID)
3517
3518
ID = OMD->getClassInterface ();
@@ -3526,7 +3527,7 @@ llvm::DISubprogram *CGDebugInfo::getObjCMethodDeclaration(
3526
3527
InterfaceType, getObjCMethodName (OMD), StringRef (),
3527
3528
InterfaceType->getFile (), LineNo, FnType, LineNo, Flags, SPFlags);
3528
3529
DBuilder.finalizeSubprogram (FD);
3529
- ObjCMethodCache[ID].push_back (FD );
3530
+ ObjCMethodCache[ID].push_back ({FD, OMD-> isDirectMethod ()} );
3530
3531
return FD;
3531
3532
}
3532
3533
@@ -4751,27 +4752,28 @@ void CGDebugInfo::finalize() {
4751
4752
DBuilder.replaceTemporary (llvm::TempDIType (E.Decl ), Ty);
4752
4753
}
4753
4754
4754
- if (CGM.getCodeGenOpts ().DwarfVersion >= 5 ) {
4755
- // Add methods to interface.
4756
- for (const auto &P : ObjCMethodCache) {
4757
- if (P.second .empty ())
4758
- continue ;
4755
+ // Add methods to interface.
4756
+ for (const auto &P : ObjCMethodCache) {
4757
+ if (P.second .empty ())
4758
+ continue ;
4759
4759
4760
- QualType QTy (P.first ->getTypeForDecl (), 0 );
4761
- auto It = TypeCache.find (QTy.getAsOpaquePtr ());
4762
- assert (It != TypeCache.end ());
4760
+ QualType QTy (P.first ->getTypeForDecl (), 0 );
4761
+ auto It = TypeCache.find (QTy.getAsOpaquePtr ());
4762
+ assert (It != TypeCache.end ());
4763
4763
4764
- llvm::DICompositeType *InterfaceDecl =
4765
- cast<llvm::DICompositeType>(It->second );
4764
+ llvm::DICompositeType *InterfaceDecl =
4765
+ cast<llvm::DICompositeType>(It->second );
4766
4766
4767
- SmallVector<llvm::Metadata *, 16 > EltTys;
4768
- auto CurrenetElts = InterfaceDecl->getElements ();
4769
- EltTys.append (CurrenetElts.begin (), CurrenetElts.end ());
4770
- for (auto &MD : P.second )
4771
- EltTys.push_back (MD);
4772
- llvm::DINodeArray Elements = DBuilder.getOrCreateArray (EltTys);
4773
- DBuilder.replaceArrays (InterfaceDecl, Elements);
4774
- }
4767
+ auto CurElts = InterfaceDecl->getElements ();
4768
+ SmallVector<llvm::Metadata *, 16 > EltTys (CurElts.begin (), CurElts.end ());
4769
+
4770
+ // For DWARF v4 or earlier, only add objc_direct methods.
4771
+ for (auto &SubprogramDirect : P.second )
4772
+ if (CGM.getCodeGenOpts ().DwarfVersion >= 5 || SubprogramDirect.getInt ())
4773
+ EltTys.push_back (SubprogramDirect.getPointer ());
4774
+
4775
+ llvm::DINodeArray Elements = DBuilder.getOrCreateArray (EltTys);
4776
+ DBuilder.replaceArrays (InterfaceDecl, Elements);
4775
4777
}
4776
4778
4777
4779
for (const auto &P : ReplaceMap) {
0 commit comments