Skip to content

Commit 56f2900

Browse files
author
git apple-llvm automerger
committed
Merge commit '342e28f8a941' from llvm.org/main into next
2 parents c3097f3 + 342e28f commit 56f2900

File tree

5 files changed

+55
-17
lines changed

5 files changed

+55
-17
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "llvm/IR/Attributes.h"
3939
#include "llvm/IR/CallingConv.h"
4040
#include "llvm/IR/DataLayout.h"
41+
#include "llvm/IR/DebugInfoMetadata.h"
4142
#include "llvm/IR/InlineAsm.h"
4243
#include "llvm/IR/IntrinsicInst.h"
4344
#include "llvm/IR/Intrinsics.h"
@@ -6286,6 +6287,24 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
62866287
pushDestroy(QualType::DK_nontrivial_c_struct, Ret.getAggregateAddress(),
62876288
RetTy);
62886289

6290+
// Generate function declaration DISuprogram in order to be used
6291+
// in debug info about call sites.
6292+
if (CGDebugInfo *DI = getDebugInfo()) {
6293+
// Ensure call site info would actually be emitted before collecting
6294+
// further callee info.
6295+
if (CalleeDecl && !CalleeDecl->hasAttr<NoDebugAttr>() &&
6296+
DI->getCallSiteRelatedAttrs() != llvm::DINode::FlagZero) {
6297+
CodeGenFunction CalleeCGF(CGM);
6298+
const GlobalDecl &CalleeGlobalDecl =
6299+
Callee.getAbstractInfo().getCalleeDecl();
6300+
CalleeCGF.CurGD = CalleeGlobalDecl;
6301+
FunctionArgList Args;
6302+
QualType ResTy = CalleeCGF.BuildFunctionArgList(CalleeGlobalDecl, Args);
6303+
DI->EmitFuncDeclForCallSite(
6304+
CI, DI->getFunctionType(CalleeDecl, ResTy, Args), CalleeGlobalDecl);
6305+
}
6306+
}
6307+
62896308
return Ret;
62906309
}
62916310

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5065,7 +5065,7 @@ void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc,
50655065

50665066
void CGDebugInfo::EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
50675067
QualType CalleeType,
5068-
const FunctionDecl *CalleeDecl) {
5068+
GlobalDecl CalleeGlobalDecl) {
50695069
if (!CallOrInvoke)
50705070
return;
50715071
auto *Func = dyn_cast<llvm::Function>(CallOrInvoke->getCalledOperand());
@@ -5074,6 +5074,9 @@ void CGDebugInfo::EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
50745074
if (Func->getSubprogram())
50755075
return;
50765076

5077+
const FunctionDecl *CalleeDecl =
5078+
cast<FunctionDecl>(CalleeGlobalDecl.getDecl());
5079+
50775080
// Do not emit a declaration subprogram for a function with nodebug
50785081
// attribute, or if call site info isn't required.
50795082
if (CalleeDecl->hasAttr<NoDebugAttr>() ||
@@ -5084,7 +5087,8 @@ void CGDebugInfo::EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
50845087
// create the one describing the function in order to have complete
50855088
// call site debug info.
50865089
if (!CalleeDecl->isStatic() && !CalleeDecl->isInlined())
5087-
EmitFunctionDecl(CalleeDecl, CalleeDecl->getLocation(), CalleeType, Func);
5090+
EmitFunctionDecl(CalleeGlobalDecl, CalleeDecl->getLocation(), CalleeType,
5091+
Func);
50885092
}
50895093

50905094
void CGDebugInfo::EmitInlineFunctionStart(CGBuilderTy &Builder, GlobalDecl GD) {

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ class CGDebugInfo {
515515
/// This is needed for call site debug info.
516516
void EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
517517
QualType CalleeType,
518-
const FunctionDecl *CalleeDecl);
518+
GlobalDecl CalleeGlobalDecl);
519519

520520
/// Constructs the debug code for exiting a function.
521521
void EmitFunctionEnd(CGBuilderTy &Builder, llvm::Function *Fn);
@@ -682,6 +682,10 @@ class CGDebugInfo {
682682
/// Emit symbol for debugger that holds the pointer to the vtable.
683683
void emitVTableSymbol(llvm::GlobalVariable *VTable, const CXXRecordDecl *RD);
684684

685+
/// Return flags which enable debug info emission for call sites, provided
686+
/// that it is supported and enabled.
687+
llvm::DINode::DIFlags getCallSiteRelatedAttrs() const;
688+
685689
private:
686690
/// Amend \p I's DebugLoc with \p Group (its source atom group) and \p
687691
/// Rank (lower nonzero rank is higher precedence). Does nothing if \p I
@@ -831,11 +835,6 @@ class CGDebugInfo {
831835
unsigned LineNo, StringRef LinkageName,
832836
llvm::GlobalVariable *Var, llvm::DIScope *DContext);
833837

834-
835-
/// Return flags which enable debug info emission for call sites, provided
836-
/// that it is supported and enabled.
837-
llvm::DINode::DIFlags getCallSiteRelatedAttrs() const;
838-
839838
/// Get the printing policy for producing names for debug info.
840839
PrintingPolicy getPrintingPolicy() const;
841840

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7635,15 +7635,6 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType,
76357635
E == MustTailCall, E->getExprLoc());
76367636

76377637
if (auto *CalleeDecl = dyn_cast_or_null<FunctionDecl>(TargetDecl)) {
7638-
// Generate function declaration DISuprogram in order to be used
7639-
// in debug info about call sites.
7640-
if (CGDebugInfo *DI = getDebugInfo()) {
7641-
FunctionArgList Args;
7642-
QualType ResTy = BuildFunctionArgList(CalleeDecl, Args);
7643-
DI->EmitFuncDeclForCallSite(LocalCallOrInvoke,
7644-
DI->getFunctionType(CalleeDecl, ResTy, Args),
7645-
CalleeDecl);
7646-
}
76477638
if (CalleeDecl->hasAttr<RestrictAttr>() ||
76487639
CalleeDecl->hasAttr<AllocSizeAttr>()) {
76497640
// Function has 'malloc' (aka. 'restrict') or 'alloc_size' attribute.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %clang_cc1 -O1 -triple x86_64-unknown_unknown -emit-llvm \
2+
// RUN: -debug-info-kind=standalone -dwarf-version=5 %s -o - | FileCheck %s
3+
4+
// Ensure both nonmember and member calls to declared function
5+
// have attached `DISubprogram`s.
6+
7+
int nonmember(int n);
8+
9+
struct S {
10+
int x;
11+
int member(int n);
12+
};
13+
14+
int main(int argc, char** argv) {
15+
struct S s = {};
16+
int a = s.member(argc);
17+
int b = nonmember(argc);
18+
return a + b;
19+
}
20+
21+
// CHECK: declare !dbg ![[SP1:[0-9]+]] noundef i32 @_ZN1S6memberEi(
22+
// CHECK: declare !dbg ![[SP2:[0-9]+]] noundef i32 @_Z9nonmemberi(
23+
24+
// CHECK: ![[SP1]] = !DISubprogram(name: "member", linkageName: "_ZN1S6memberEi"
25+
// CHECK: ![[SP2]] = !DISubprogram(name: "nonmember", linkageName: "_Z9nonmemberi"

0 commit comments

Comments
 (0)