Skip to content

Commit d2d7a90

Browse files
committed
[DebugInfo] convert btf_tag attrs to DI annotations for DIGlobalVariable
Generate btf_tag annotations for DIGlobalVariable. The annotations are represented as an DINodeArray in DebugInfo. Differential Revision: https://reviews.llvm.org/D106619
1 parent c62ef02 commit d2d7a90

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4828,12 +4828,13 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
48284828
}
48294829
AppendAddressSpaceXDeref(AddressSpace, Expr);
48304830

4831+
llvm::DINodeArray Annotations = CollectBTFTagAnnotations(D);
48314832
GVE = DBuilder.createGlobalVariableExpression(
48324833
DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit),
48334834
Var->hasLocalLinkage(), true,
48344835
Expr.empty() ? nullptr : DBuilder.createExpression(Expr),
48354836
getOrCreateStaticDataMemberDeclarationOrNull(D), TemplateParameters,
4836-
Align);
4837+
Align, Annotations);
48374838
Var->addDebugInfo(GVE);
48384839
}
48394840
DeclCache[D->getCanonicalDecl()].reset(GVE);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// REQUIRES: x86-registered-target
2+
// RUN: %clang -target x86_64 -g -S -emit-llvm -o - %s | FileCheck %s
3+
4+
#define __tag1 __attribute__((btf_tag("tag1")))
5+
#define __tag2 __attribute__((btf_tag("tag2")))
6+
7+
struct t1 {
8+
int a;
9+
};
10+
struct t1 g1 __tag1 __tag2;
11+
12+
extern struct t1 g2 __tag1 __tag2;
13+
struct t1 g2;
14+
15+
// CHECK: distinct !DIGlobalVariable(name: "g1", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[#]], isLocal: false, isDefinition: true, annotations: ![[ANNOT:[0-9]+]])
16+
// CHECK: distinct !DIGlobalVariable(name: "g2", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[#]], isLocal: false, isDefinition: true, annotations: ![[ANNOT]])
17+
// CHECK: ![[ANNOT]] = !{![[TAG1:[0-9]+]], ![[TAG2:[0-9]+]]}
18+
// CHECK: ![[TAG1]] = !{!"btf_tag", !"tag1"}
19+
// CHECK: ![[TAG2]] = !{!"btf_tag", !"tag2"}
20+
21+
extern struct t1 g3 __tag1;
22+
struct t1 g3 __tag2;
23+
24+
// CHECK: distinct !DIGlobalVariable(name: "g3", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[#]], isLocal: false, isDefinition: true, annotations: ![[ANNOT]])
25+
26+
extern struct t1 g4;
27+
struct t1 g4 __tag1 __tag2;
28+
29+
// CHECK: distinct !DIGlobalVariable(name: "g4", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[#]], isLocal: false, isDefinition: true, annotations: ![[ANNOT]])

0 commit comments

Comments
 (0)