@@ -2569,8 +2569,8 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const ObjCInterfaceType *Ty,
2569
2569
SourceLocation Loc = PD->getLocation ();
2570
2570
llvm::DIFile *PUnit = getOrCreateFile (Loc);
2571
2571
unsigned PLine = getLineNumber (Loc);
2572
- ObjCMethodDecl *Getter = PD ->getGetterMethodDecl ();
2573
- ObjCMethodDecl *Setter = PD ->getSetterMethodDecl ();
2572
+ ObjCMethodDecl *Getter = PImpD ->getGetterMethodDecl ();
2573
+ ObjCMethodDecl *Setter = PImpD ->getSetterMethodDecl ();
2574
2574
PropertyNode = DBuilder.createObjCProperty (
2575
2575
PD->getName (), PUnit, PLine,
2576
2576
hasDefaultGetterName (PD, Getter)
@@ -3445,6 +3445,38 @@ llvm::DISubprogram *CGDebugInfo::getFunctionDeclaration(const Decl *D) {
3445
3445
return nullptr ;
3446
3446
}
3447
3447
3448
+ llvm::DISubprogram *CGDebugInfo::getObjCMethodDeclaration (
3449
+ const Decl *D, llvm::DISubroutineType *FnType, unsigned LineNo,
3450
+ llvm::DINode::DIFlags Flags, llvm::DISubprogram::DISPFlags SPFlags) {
3451
+ if (!D || DebugKind <= codegenoptions::DebugLineTablesOnly)
3452
+ return nullptr ;
3453
+
3454
+ if (CGM.getCodeGenOpts ().DwarfVersion < 5 )
3455
+ return nullptr ;
3456
+
3457
+ // Starting with DWARF V5 method declarations are emitted as children of
3458
+ // the interface type.
3459
+ const auto *OMD = dyn_cast<ObjCMethodDecl>(D);
3460
+ if (!OMD)
3461
+ return nullptr ;
3462
+ auto *ID = dyn_cast_or_null<ObjCInterfaceDecl>(D->getDeclContext ());
3463
+ if (!ID)
3464
+ ID = OMD->getClassInterface ();
3465
+ if (!ID)
3466
+ return nullptr ;
3467
+ QualType QTy (ID->getTypeForDecl (), 0 );
3468
+ auto It = TypeCache.find (QTy.getAsOpaquePtr ());
3469
+ if (It == TypeCache.end ())
3470
+ return nullptr ;
3471
+ auto *InterfaceType = cast<llvm::DICompositeType>(It->second );
3472
+ llvm::DISubprogram *FD = DBuilder.createFunction (
3473
+ InterfaceType, getObjCMethodName (OMD), StringRef (),
3474
+ InterfaceType->getFile (), LineNo, FnType, LineNo, Flags, SPFlags);
3475
+ DBuilder.finalizeSubprogram (FD);
3476
+ ObjCMethodCache[ID].push_back (FD);
3477
+ return FD;
3478
+ }
3479
+
3448
3480
// getOrCreateFunctionType - Construct type. If it is a c++ method, include
3449
3481
// implicit parameter "this".
3450
3482
llvm::DISubroutineType *CGDebugInfo::getOrCreateFunctionType (const Decl *D,
@@ -3587,43 +3619,28 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, SourceLocation Loc,
3587
3619
3588
3620
unsigned LineNo = getLineNumber (Loc);
3589
3621
unsigned ScopeLine = getLineNumber (ScopeLoc);
3622
+ llvm::DISubroutineType *DIFnType = getOrCreateFunctionType (D, FnType, Unit);
3623
+ llvm::DISubprogram *Decl = nullptr ;
3624
+ if (D)
3625
+ Decl = isa<ObjCMethodDecl>(D)
3626
+ ? getObjCMethodDeclaration (D, DIFnType, LineNo, Flags, SPFlags)
3627
+ : getFunctionDeclaration (D);
3590
3628
3591
3629
// FIXME: The function declaration we're constructing here is mostly reusing
3592
3630
// declarations from CXXMethodDecl and not constructing new ones for arbitrary
3593
3631
// FunctionDecls. When/if we fix this we can have FDContext be TheCU/null for
3594
3632
// all subprograms instead of the actual context since subprogram definitions
3595
3633
// are emitted as CU level entities by the backend.
3596
3634
llvm::DISubprogram *SP = DBuilder.createFunction (
3597
- FDContext, Name, LinkageName, Unit, LineNo,
3598
- getOrCreateFunctionType (D, FnType, Unit), ScopeLine, FlagsForDef,
3599
- SPFlagsForDef, TParamsArray.get (), getFunctionDeclaration (D));
3635
+ FDContext, Name, LinkageName, Unit, LineNo, DIFnType, ScopeLine,
3636
+ FlagsForDef, SPFlagsForDef, TParamsArray.get (), Decl);
3600
3637
Fn->setSubprogram (SP);
3601
3638
// We might get here with a VarDecl in the case we're generating
3602
3639
// code for the initialization of globals. Do not record these decls
3603
3640
// as they will overwrite the actual VarDecl Decl in the cache.
3604
3641
if (HasDecl && isa<FunctionDecl>(D))
3605
3642
DeclCache[D->getCanonicalDecl ()].reset (SP);
3606
3643
3607
- if (CGM.getCodeGenOpts ().DwarfVersion >= 5 ) {
3608
- // Starting with DWARF V5 method declarations are emitted as children of
3609
- // the interface type.
3610
- if (const auto *OMD = dyn_cast_or_null<ObjCMethodDecl>(D)) {
3611
- const ObjCInterfaceDecl *ID = OMD->getClassInterface ();
3612
- QualType QTy (ID->getTypeForDecl (), 0 );
3613
- auto It = TypeCache.find (QTy.getAsOpaquePtr ());
3614
- if (It != TypeCache.end ()) {
3615
- llvm::DICompositeType *InterfaceDecl =
3616
- cast<llvm::DICompositeType>(It->second );
3617
- llvm::DISubprogram *FD = DBuilder.createFunction (
3618
- InterfaceDecl, Name, LinkageName, Unit, LineNo,
3619
- getOrCreateFunctionType (D, FnType, Unit), ScopeLine, Flags, SPFlags,
3620
- TParamsArray.get ());
3621
- DBuilder.finalizeSubprogram (FD);
3622
- ObjCMethodCache[ID].push_back (FD);
3623
- }
3624
- }
3625
- }
3626
-
3627
3644
// Push the function onto the lexical block stack.
3628
3645
LexicalBlockStack.emplace_back (SP);
3629
3646
0 commit comments