[clang] d2d7a90 - [DebugInfo] convert btf_tag attrs to DI annotations for DIGlobalVariable

Yonghong Song via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 26 10:36:48 PDT 2021


Author: Yonghong Song
Date: 2021-08-26T10:36:33-07:00
New Revision: d2d7a90ceded94251905b7adcd5eb2ac5191896f

URL: https://github.com/llvm/llvm-project/commit/d2d7a90ceded94251905b7adcd5eb2ac5191896f
DIFF: https://github.com/llvm/llvm-project/commit/d2d7a90ceded94251905b7adcd5eb2ac5191896f.diff

LOG: [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

Added: 
    clang/test/CodeGen/attr-btf_tag-diglobalvariable.c

Modified: 
    clang/lib/CodeGen/CGDebugInfo.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 57f915028dde..2de933f65800 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4828,12 +4828,13 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
     }
     AppendAddressSpaceXDeref(AddressSpace, Expr);
 
+    llvm::DINodeArray Annotations = CollectBTFTagAnnotations(D);
     GVE = DBuilder.createGlobalVariableExpression(
         DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit),
         Var->hasLocalLinkage(), true,
         Expr.empty() ? nullptr : DBuilder.createExpression(Expr),
         getOrCreateStaticDataMemberDeclarationOrNull(D), TemplateParameters,
-        Align);
+        Align, Annotations);
     Var->addDebugInfo(GVE);
   }
   DeclCache[D->getCanonicalDecl()].reset(GVE);

diff  --git a/clang/test/CodeGen/attr-btf_tag-diglobalvariable.c b/clang/test/CodeGen/attr-btf_tag-diglobalvariable.c
new file mode 100644
index 000000000000..e8b20a202990
--- /dev/null
+++ b/clang/test/CodeGen/attr-btf_tag-diglobalvariable.c
@@ -0,0 +1,29 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang -target x86_64 -g -S -emit-llvm -o - %s | FileCheck %s
+
+#define __tag1 __attribute__((btf_tag("tag1")))
+#define __tag2 __attribute__((btf_tag("tag2")))
+
+struct t1 {
+  int a;
+};
+struct t1 g1 __tag1 __tag2;
+
+extern struct t1 g2 __tag1 __tag2;
+struct t1 g2;
+
+// CHECK: distinct !DIGlobalVariable(name: "g1", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[#]], isLocal: false, isDefinition: true, annotations: ![[ANNOT:[0-9]+]])
+// CHECK: distinct !DIGlobalVariable(name: "g2", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[#]], isLocal: false, isDefinition: true, annotations: ![[ANNOT]])
+// CHECK: ![[ANNOT]] = !{![[TAG1:[0-9]+]], ![[TAG2:[0-9]+]]}
+// CHECK: ![[TAG1]] = !{!"btf_tag", !"tag1"}
+// CHECK: ![[TAG2]] = !{!"btf_tag", !"tag2"}
+
+extern struct t1 g3 __tag1;
+struct t1 g3 __tag2;
+
+// CHECK: distinct !DIGlobalVariable(name: "g3", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[#]], isLocal: false, isDefinition: true, annotations: ![[ANNOT]])
+
+extern struct t1 g4;
+struct t1 g4 __tag1 __tag2;
+
+// CHECK: distinct !DIGlobalVariable(name: "g4", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[#]], isLocal: false, isDefinition: true, annotations: ![[ANNOT]])


        


More information about the cfe-commits mailing list