Skip to content

Commit 58bdf8f

Browse files
eddyz87yonghong-song
authored andcommitted
[BPF] preserve btf_decl_tag for parameters of extern functions
Generate DILocalVariable entries for parameters of extern functions, the "annotations" field of DILocalVariable is used to link "btf_decl_tag" annotation with the parameter. Do this only for BPF backend as there are no other users for this information. Final DWARF is valid as "Appendix A" is very much lax in what is allowed as attributes for "DW_TAG_formal_parameter": DWARF does not in general require that a given debugging information entry contain a particular attribute or set of attributes. Instead, a DWARF producer is free to generate any, all, or none of the attributes ... other attributes ... may also appear in a given debugging information entry. DWARF Debugging Information Format Version 5, Appendix A: Attributes by Tag Value (Informative) Page 251, Line 3. Differential Revision: https://reviews.llvm.org/D140970
1 parent 5702202 commit 58bdf8f

File tree

2 files changed

+60
-4
lines changed

2 files changed

+60
-4
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4206,10 +4206,28 @@ void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc,
42064206
SPFlags |= llvm::DISubprogram::SPFlagOptimized;
42074207

42084208
llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
4209-
llvm::DISubprogram *SP = DBuilder.createFunction(
4210-
FDContext, Name, LinkageName, Unit, LineNo,
4211-
getOrCreateFunctionType(D, FnType, Unit), ScopeLine, Flags, SPFlags,
4212-
TParamsArray.get(), getFunctionDeclaration(D), nullptr, Annotations);
4209+
llvm::DISubroutineType *STy = getOrCreateFunctionType(D, FnType, Unit);
4210+
llvm::DISubprogram *SP =
4211+
DBuilder.createFunction(FDContext, Name, LinkageName, Unit, LineNo, STy,
4212+
ScopeLine, Flags, SPFlags, TParamsArray.get(),
4213+
getFunctionDeclaration(D), nullptr, Annotations);
4214+
4215+
// Preserve btf_decl_tag attributes for parameters of extern functions
4216+
// for BPF target. The parameters created in this loop are attached as
4217+
// DISubprogram's retainedNodes in the subsequent finalizeSubprogram call.
4218+
if (IsDeclForCallSite && CGM.getTarget().getTriple().isBPF()) {
4219+
if (auto *FD = dyn_cast<FunctionDecl>(D)) {
4220+
llvm::DITypeRefArray ParamTypes = STy->getTypeArray();
4221+
unsigned ArgNo = 1;
4222+
for (ParmVarDecl *PD : FD->parameters()) {
4223+
llvm::DINodeArray ParamAnnotations = CollectBTFDeclTagAnnotations(PD);
4224+
DBuilder.createParameterVariable(
4225+
SP, PD->getName(), ArgNo, Unit, LineNo, ParamTypes[ArgNo], true,
4226+
llvm::DINode::FlagZero, ParamAnnotations);
4227+
++ArgNo;
4228+
}
4229+
}
4230+
}
42134231

42144232
if (IsDeclForCallSite)
42154233
Fn->setSubprogram(SP);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// REQUIRES: bpf-registered-target
2+
// RUN: %clang -target bpf -S -emit-llvm -g -O2 -o - %s | FileCheck %s
3+
4+
#define __decl_tag(x) __attribute__((btf_decl_tag(x)))
5+
6+
extern void foo(int aa __decl_tag("aa_tag"), long bb __decl_tag("bb_tag"));
7+
extern void bar(char cc __decl_tag("cc_tag"));
8+
extern void buz(int __decl_tag("buz_arg_tag"));
9+
10+
void root(void) {
11+
foo(0, 1);
12+
bar(0);
13+
buz(0);
14+
}
15+
// CHECK: [[foo:![0-9]+]] = !DISubprogram(name: "foo", {{.*}}, retainedNodes: [[foo_nodes:![0-9]+]])
16+
// CHECK: [[foo_nodes]] = !{[[aa:![0-9]+]], [[bb:![0-9]+]]}
17+
18+
// CHECK: [[aa]] = !DILocalVariable(name: "aa", arg: 1, scope: [[foo]], {{.*}}, annotations: [[aa_annot:![0-9]+]])
19+
// CHECK: [[aa_annot]] = !{[[aa_tag:![0-9]+]]}
20+
// CHECK: [[aa_tag]] = !{!"btf_decl_tag", !"aa_tag"}
21+
22+
// CHECK: [[bb]] = !DILocalVariable(name: "bb", arg: 2, scope: [[foo]], {{.*}}, annotations: [[bb_annot:![0-9]+]])
23+
// CHECK: [[bb_annot]] = !{[[bb_tag:![0-9]+]]}
24+
// CHECK: [[bb_tag]] = !{!"btf_decl_tag", !"bb_tag"}
25+
26+
// CHECK: [[bar:![0-9]+]] = !DISubprogram(name: "bar", {{.*}}, retainedNodes: [[bar_nodes:![0-9]+]])
27+
// CHECK: [[bar_nodes]] = !{[[cc:![0-9]+]]}
28+
29+
// CHECK: [[cc]] = !DILocalVariable(name: "cc", arg: 1, scope: [[bar]], {{.*}}, annotations: [[cc_annot:![0-9]+]])
30+
// CHECK: [[cc_annot]] = !{[[cc_tag:![0-9]+]]}
31+
// CHECK: [[cc_tag]] = !{!"btf_decl_tag", !"cc_tag"}
32+
33+
// CHECK: [[buz:![0-9]+]] = !DISubprogram(name: "buz", {{.*}}, retainedNodes: [[buz_nodes:![0-9]+]])
34+
// CHECK: [[buz_nodes]] = !{[[buz_arg:![0-9]+]]}
35+
36+
// CHECK: [[buz_arg]] = !DILocalVariable(arg: 1, scope: [[buz]], {{.*}}, annotations: [[buz_arg_annot:![0-9]+]])
37+
// CHECK: [[buz_arg_annot]] = !{[[buz_arg_tag:![0-9]+]]}
38+
// CHECK: [[buz_arg_tag]] = !{!"btf_decl_tag", !"buz_arg_tag"}

0 commit comments

Comments
 (0)