yonghong-song updated this revision to Diff 374073.
yonghong-song added a comment.

- updated tests based on @probinson suggestions.
- The only thing left is for llvm/test/DebugInfo/X86/attr-btf_tag-typedef.ll 
for which I didn't use `%itanium_abi_triple` as it seems only available for 
%clang ... and not available for llc.

  [$ ~/work/llvm-project/llvm/test] egrep -r itanium_abi_triple
  [$~/work/llvm-project/llvm/test]


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110129/new/

https://reviews.llvm.org/D110129

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/attr-btf_tag-typedef.c
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/test/Bitcode/attr-btf_tag-typedef.ll
  llvm/test/DebugInfo/X86/attr-btf_tag-typedef.ll

Index: llvm/test/DebugInfo/X86/attr-btf_tag-typedef.ll
===================================================================
--- /dev/null
+++ llvm/test/DebugInfo/X86/attr-btf_tag-typedef.ll
@@ -0,0 +1,69 @@
+; RUN: llc -mtriple=x86_64-linux -filetype=obj -o %t %s
+; RUN: llvm-dwarfdump -debug-info %t | FileCheck %s
+;
+; Source:
+;   #define __tag1 __attribute__((btf_tag("tag1")))
+;   typedef struct { int a; } __s __tag1;
+;   typedef unsigned __tag1 * __u;
+;   __s a;
+;   __u u;
+; Compilation flag:
+;   clang -S -g -emit-llvm typedef.c
+
+%struct.__s = type { i32 }
+
+@a = dso_local global %struct.__s zeroinitializer, align 4, !dbg !0
+@u = dso_local global i32* null, align 8, !dbg !5
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!17, !18, !19, !20, !21}
+!llvm.ident = !{!22}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !3, line: 4, type: !12, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 14.0.0 (https://github.com/llvm/llvm-project.git b9757992b73e823edf1fa699372ff9cd29db6cb7)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "typedef.c", directory: "/home/yhs/work/tests/llvm/btf_tag")
+!4 = !{!0, !5}
+!5 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression())
+!6 = distinct !DIGlobalVariable(name: "u", scope: !2, file: !3, line: 5, type: !7, isLocal: false, isDefinition: true)
+!7 = !DIDerivedType(tag: DW_TAG_typedef, name: "__u", file: !3, line: 3, baseType: !8, annotations: !10)
+!8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64)
+!9 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
+!10 = !{!11}
+!11 = !{!"btf_tag", !"tag1"}
+!12 = !DIDerivedType(tag: DW_TAG_typedef, name: "__s", file: !3, line: 2, baseType: !13, annotations: !10)
+!13 = distinct !DICompositeType(tag: DW_TAG_structure_type, file: !3, line: 2, size: 32, elements: !14)
+!14 = !{!15}
+!15 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !13, file: !3, line: 2, baseType: !16, size: 32)
+!16 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+
+; CHECK:        DW_TAG_typedef
+; CHECK-NEXT:     DW_AT_type
+; CHECK-NEXT:     DW_AT_name      ("__s")
+; CHECK-NEXT:     DW_AT_decl_file
+; CHECK-NEXT:     DW_AT_decl_line
+; CHECK-EMPTY:
+; CHECK-NEXT:     DW_TAG_LLVM_annotation
+; CHECK-NEXT:       DW_AT_name    ("btf_tag")
+; CHECK-NEXT:       DW_AT_const_value     ("tag1")
+; CHECK-EMPTY:
+; CHECK-NEXT:     NULL
+
+; CHECK:        DW_TAG_typedef
+; CHECK-NEXT:     DW_AT_type
+; CHECK-NEXT:     DW_AT_name      ("__u")
+; CHECK-NEXT:     DW_AT_decl_file
+; CHECK-NEXT:     DW_AT_decl_line
+; CHECK-EMPTY:
+; CHECK-NEXT:     DW_TAG_LLVM_annotation
+; CHECK-NEXT:       DW_AT_name    ("btf_tag")
+; CHECK-NEXT:       DW_AT_const_value     ("tag1")
+; CHECK-EMPTY:
+; CHECK-NEXT:     NULL
+
+!17 = !{i32 7, !"Dwarf Version", i32 4}
+!18 = !{i32 2, !"Debug Info Version", i32 3}
+!19 = !{i32 1, !"wchar_size", i32 4}
+!20 = !{i32 7, !"uwtable", i32 1}
+!21 = !{i32 7, !"frame-pointer", i32 2}
+!22 = !{!"clang version 14.0.0 (https://github.com/llvm/llvm-project.git b9757992b73e823edf1fa699372ff9cd29db6cb7)"}
Index: llvm/test/Bitcode/attr-btf_tag-typedef.ll
===================================================================
--- /dev/null
+++ llvm/test/Bitcode/attr-btf_tag-typedef.ll
@@ -0,0 +1,54 @@
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
+;
+; Source:
+;   #define __tag1 __attribute__((btf_tag("tag1")))
+;   typedef struct { int a; } __s __tag1;
+;   typedef unsigned __tag1 * __u;
+;   __s a;
+;   __u u;
+; Compilation flag:
+;   clang -S -g -emit-llvm typedef.c
+
+%struct.__s = type { i32 }
+
+@a = dso_local global %struct.__s zeroinitializer, align 4, !dbg !0
+@u = dso_local global i32* null, align 8, !dbg !5
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!17, !18, !19, !20, !21}
+!llvm.ident = !{!22}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !3, line: 4, type: !12, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 14.0.0 (https://github.com/llvm/llvm-project.git b9757992b73e823edf1fa699372ff9cd29db6cb7)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "typedef.c", directory: "/home/yhs/work/tests/llvm/btf_tag")
+!4 = !{!0, !5}
+!5 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression())
+!6 = distinct !DIGlobalVariable(name: "u", scope: !2, file: !3, line: 5, type: !7, isLocal: false, isDefinition: true)
+!7 = !DIDerivedType(tag: DW_TAG_typedef, name: "__u", file: !3, line: 3, baseType: !8, annotations: !10)
+!8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64)
+!9 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
+!10 = !{!11}
+!11 = !{!"btf_tag", !"tag1"}
+
+; CHECK:      !DIDerivedType(tag: DW_TAG_typedef, name: "__u"
+; CHECK-SAME: annotations: ![[ANNOT:[0-9]+]]
+; CHECK:      ![[ANNOT]] = !{![[TAG1:[0-9]+]]}
+; CHECK:      ![[TAG1]] = !{!"btf_tag", !"tag1"}
+
+!12 = !DIDerivedType(tag: DW_TAG_typedef, name: "__s", file: !3, line: 2, baseType: !13, annotations: !10)
+
+; CHECK:      !DIDerivedType(tag: DW_TAG_typedef, name: "__s"
+; CHECK-SAME: annotations: ![[ANNOT]]
+
+!13 = distinct !DICompositeType(tag: DW_TAG_structure_type, file: !3, line: 2, size: 32, elements: !14)
+!14 = !{!15}
+!15 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !13, file: !3, line: 2, baseType: !16, size: 32)
+
+!16 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!17 = !{i32 7, !"Dwarf Version", i32 4}
+!18 = !{i32 2, !"Debug Info Version", i32 3}
+!19 = !{i32 1, !"wchar_size", i32 4}
+!20 = !{i32 7, !"uwtable", i32 1}
+!21 = !{i32 7, !"frame-pointer", i32 2}
+!22 = !{!"clang version 14.0.0 (https://github.com/llvm/llvm-project.git b9757992b73e823edf1fa699372ff9cd29db6cb7)"}
Index: llvm/lib/IR/DIBuilder.cpp
===================================================================
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -324,10 +324,12 @@
 DIDerivedType *DIBuilder::createTypedef(DIType *Ty, StringRef Name,
                                         DIFile *File, unsigned LineNo,
                                         DIScope *Context,
-                                        uint32_t AlignInBits) {
+                                        uint32_t AlignInBits,
+                                        DINodeArray Annotations) {
   return DIDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name, File,
                             LineNo, getNonCompileUnitScope(Context), Ty, 0,
-                            AlignInBits, 0, None, DINode::FlagZero);
+                            AlignInBits, 0, None, DINode::FlagZero, nullptr,
+                            Annotations);
 }
 
 DIDerivedType *DIBuilder::createFriend(DIType *Ty, DIType *FriendTy) {
Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -754,6 +754,8 @@
   if (!Name.empty())
     addString(Buffer, dwarf::DW_AT_name, Name);
 
+  addAnnotation(Buffer, DTy->getAnnotations());
+
   // If alignment is specified for a typedef , create and insert DW_AT_alignment
   // attribute in DW_TAG_typedef DIE.
   if (Tag == dwarf::DW_TAG_typedef && DD->getDwarfVersion() >= 5) {
Index: llvm/include/llvm/IR/DIBuilder.h
===================================================================
--- llvm/include/llvm/IR/DIBuilder.h
+++ llvm/include/llvm/IR/DIBuilder.h
@@ -250,9 +250,11 @@
     /// \param LineNo      Line number.
     /// \param Context     The surrounding context for the typedef.
     /// \param AlignInBits Alignment. (optional)
+    /// \param Annotations Annotations. (optional)
     DIDerivedType *createTypedef(DIType *Ty, StringRef Name, DIFile *File,
                                  unsigned LineNo, DIScope *Context,
-                                 uint32_t AlignInBits = 0);
+                                 uint32_t AlignInBits = 0,
+                                 DINodeArray Annotations = nullptr);
 
     /// Create debugging information entry for a 'friend'.
     DIDerivedType *createFriend(DIType *Ty, DIType *FriendTy);
Index: clang/test/CodeGen/attr-btf_tag-typedef.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/attr-btf_tag-typedef.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -debug-info-kind=limited -S -emit-llvm -o - %s | FileCheck %s
+
+#define __tag1 __attribute__((btf_tag("tag1")))
+typedef struct { int a; } __s __tag1;
+typedef unsigned __tag1 * __u;
+__s a;
+__u u;
+
+// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "__u", file: ![[#]], line: [[#]], baseType: ![[#]], annotations: ![[ANNOT:[0-9]+]])
+// CHECK: ![[ANNOT]] = !{![[TAG1:[0-9]+]]}
+// CHECK: ![[TAG1]] = !{!"btf_tag", !"tag1"}
+
+// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "__s", file: ![[#]], line: [[#]], baseType: ![[#]], annotations: ![[ANNOT]])
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1287,9 +1287,11 @@
 
   uint32_t Align = getDeclAlignIfRequired(Ty->getDecl(), CGM.getContext());
   // Typedefs are derived from some other type.
+  llvm::DINodeArray Annotations = CollectBTFTagAnnotations(Ty->getDecl());
   return DBuilder.createTypedef(Underlying, Ty->getDecl()->getName(),
                                 getOrCreateFile(Loc), getLineNumber(Loc),
-                                getDeclContextDescriptor(Ty->getDecl()), Align);
+                                getDeclContextDescriptor(Ty->getDecl()), Align,
+                                Annotations);
 }
 
 static unsigned getDwarfCC(CallingConv CC) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to