@@ -2600,8 +2600,8 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const ObjCInterfaceType *Ty,
2600
2600
SourceLocation Loc = PD->getLocation ();
2601
2601
llvm::DIFile *PUnit = getOrCreateFile (Loc);
2602
2602
unsigned PLine = getLineNumber (Loc);
2603
- ObjCMethodDecl *Getter = PD ->getGetterMethodDecl ();
2604
- ObjCMethodDecl *Setter = PD ->getSetterMethodDecl ();
2603
+ ObjCMethodDecl *Getter = PImpD ->getGetterMethodDecl ();
2604
+ ObjCMethodDecl *Setter = PImpD ->getSetterMethodDecl ();
2605
2605
PropertyNode = DBuilder.createObjCProperty (
2606
2606
PD->getName (), PUnit, PLine,
2607
2607
hasDefaultGetterName (PD, Getter)
@@ -3490,6 +3490,38 @@ llvm::DISubprogram *CGDebugInfo::getFunctionDeclaration(const Decl *D) {
3490
3490
return nullptr ;
3491
3491
}
3492
3492
3493
+ llvm::DISubprogram *CGDebugInfo::getObjCMethodDeclaration (
3494
+ const Decl *D, llvm::DISubroutineType *FnType, unsigned LineNo,
3495
+ llvm::DINode::DIFlags Flags, llvm::DISubprogram::DISPFlags SPFlags) {
3496
+ if (!D || DebugKind <= codegenoptions::DebugLineTablesOnly)
3497
+ return nullptr ;
3498
+
3499
+ if (CGM.getCodeGenOpts ().DwarfVersion < 5 )
3500
+ return nullptr ;
3501
+
3502
+ // Starting with DWARF V5 method declarations are emitted as children of
3503
+ // the interface type.
3504
+ const auto *OMD = dyn_cast<ObjCMethodDecl>(D);
3505
+ if (!OMD)
3506
+ return nullptr ;
3507
+ auto *ID = dyn_cast_or_null<ObjCInterfaceDecl>(D->getDeclContext ());
3508
+ if (!ID)
3509
+ ID = OMD->getClassInterface ();
3510
+ if (!ID)
3511
+ return nullptr ;
3512
+ QualType QTy (ID->getTypeForDecl (), 0 );
3513
+ auto It = TypeCache.find (QTy.getAsOpaquePtr ());
3514
+ if (It == TypeCache.end ())
3515
+ return nullptr ;
3516
+ auto *InterfaceType = cast<llvm::DICompositeType>(It->second );
3517
+ llvm::DISubprogram *FD = DBuilder.createFunction (
3518
+ InterfaceType, getObjCMethodName (OMD), StringRef (),
3519
+ InterfaceType->getFile (), LineNo, FnType, LineNo, Flags, SPFlags);
3520
+ DBuilder.finalizeSubprogram (FD);
3521
+ ObjCMethodCache[ID].push_back (FD);
3522
+ return FD;
3523
+ }
3524
+
3493
3525
// getOrCreateFunctionType - Construct type. If it is a c++ method, include
3494
3526
// implicit parameter "this".
3495
3527
llvm::DISubroutineType *CGDebugInfo::getOrCreateFunctionType (const Decl *D,
@@ -3632,16 +3664,21 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, SourceLocation Loc,
3632
3664
3633
3665
unsigned LineNo = getLineNumber (Loc);
3634
3666
unsigned ScopeLine = getLineNumber (ScopeLoc);
3667
+ llvm::DISubroutineType *DIFnType = getOrCreateFunctionType (D, FnType, Unit);
3668
+ llvm::DISubprogram *Decl = nullptr ;
3669
+ if (D)
3670
+ Decl = isa<ObjCMethodDecl>(D)
3671
+ ? getObjCMethodDeclaration (D, DIFnType, LineNo, Flags, SPFlags)
3672
+ : getFunctionDeclaration (D);
3635
3673
3636
3674
// FIXME: The function declaration we're constructing here is mostly reusing
3637
3675
// declarations from CXXMethodDecl and not constructing new ones for arbitrary
3638
3676
// FunctionDecls. When/if we fix this we can have FDContext be TheCU/null for
3639
3677
// all subprograms instead of the actual context since subprogram definitions
3640
3678
// are emitted as CU level entities by the backend.
3641
3679
llvm::DISubprogram *SP = DBuilder.createFunction (
3642
- FDContext, Name, LinkageName, Unit, LineNo,
3643
- getOrCreateFunctionType (D, FnType, Unit), ScopeLine, FlagsForDef,
3644
- SPFlagsForDef, TParamsArray.get (), getFunctionDeclaration (D));
3680
+ FDContext, Name, LinkageName, Unit, LineNo, DIFnType, ScopeLine,
3681
+ FlagsForDef, SPFlagsForDef, TParamsArray.get (), Decl);
3645
3682
Fn->setSubprogram (SP);
3646
3683
// We might get here with a VarDecl in the case we're generating
3647
3684
// code for the initialization of globals. Do not record these decls
@@ -3658,26 +3695,6 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, SourceLocation Loc,
3658
3695
if (FD->hasBody () && !FD->param_empty ())
3659
3696
SPDefCache[FD].reset (SP);
3660
3697
3661
- if (CGM.getCodeGenOpts ().DwarfVersion >= 5 ) {
3662
- // Starting with DWARF V5 method declarations are emitted as children of
3663
- // the interface type.
3664
- if (const auto *OMD = dyn_cast_or_null<ObjCMethodDecl>(D)) {
3665
- const ObjCInterfaceDecl *ID = OMD->getClassInterface ();
3666
- QualType QTy (ID->getTypeForDecl (), 0 );
3667
- auto It = TypeCache.find (QTy.getAsOpaquePtr ());
3668
- if (It != TypeCache.end ()) {
3669
- llvm::DICompositeType *InterfaceDecl =
3670
- cast<llvm::DICompositeType>(It->second );
3671
- llvm::DISubprogram *FD = DBuilder.createFunction (
3672
- InterfaceDecl, Name, LinkageName, Unit, LineNo,
3673
- getOrCreateFunctionType (D, FnType, Unit), ScopeLine, Flags, SPFlags,
3674
- TParamsArray.get ());
3675
- DBuilder.finalizeSubprogram (FD);
3676
- ObjCMethodCache[ID].push_back (FD);
3677
- }
3678
- }
3679
- }
3680
-
3681
3698
// Push the function onto the lexical block stack.
3682
3699
LexicalBlockStack.emplace_back (SP);
3683
3700
0 commit comments