[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2022-05-20 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

@compnerd Thanks for reporting. I will take a look as soon as possible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2022-05-20 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added a comment.
Herald added a project: All.

The sema portions of this change are still causing an issue.  Although the 
revert (rGf95bd18b5faa6a5af4b5786312c373c5b2dce687 
) and the 
subsequent re-application in rG3466e00716e12e32fdb100e3fcfca5c2b3e8d784 
  
addressed the debug info issue, the Sema issue remains.

  // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c11 -x c %s
  struct dispatch_object_s;
  void _dispatch_queue_get_head(struct dispatch_object_s * volatile 
dq_items_head) {
(_Atomic __typeof__(dq_items_head) *)dq_items_head;
  }

will trigger an assertion failure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-11-06 Thread Yonghong Song via cfe-commits



On 11/6/21 4:36 PM, Nathan Chancellor via Phabricator wrote:

nathanchance added a comment.

I bisected a crash in the Linux kernel down to the reland commit (and it is not 
fixed as of 
https://github.com/llvm/llvm-project/commit/2249ecee8d9a6237f51485bd39f01ba031575987):

   $ git bisect log
   # bad: [bdaa181007a46d317a1665acb8234eddeee82815] 
[TwoAddressInstructionPass] Update existing physreg live intervals
   # good: [d4b1cf8f9c48a49ab808df15c4ab378276a07b82] [OpenMP] Build device 
runtimes for sm_86
   git bisect start 'bdaa181007a46d317a1665acb8234eddeee82815' 
'd4b1cf8f9c48a49ab808df15c4ab378276a07b82'
   # good: [f2703c3c3353031de8de8c465a59d31488b11fb3] [DAG] FoldConstantArithmetic 
- rename NumOps -> NumElts. NFC.
   git bisect good f2703c3c3353031de8de8c465a59d31488b11fb3
   # good: [c68183b81e5257186c9403cf91f8b958af7459bc] [gn build] Use `=` for of 
-fdebug-compilation-dir
   git bisect good c68183b81e5257186c9403cf91f8b958af7459bc
   # bad: [2d8ec3c61d3c2d47b303187bb882ca23544f6fc5] [libcxx] [test] Narrow down XFAILs regarding 
a MSVC mode specific bug to "windows-dll && msvc"
   git bisect bad 2d8ec3c61d3c2d47b303187bb882ca23544f6fc5
   # good: [97c899f3c5d9bbff2824b3252b21378bf96f3f3f] [mlir] Add callback to 
provide a pass pipeline to MlirOptMain
   git bisect good 97c899f3c5d9bbff2824b3252b21378bf96f3f3f
   # bad: [4070f305f9a0c488d7177754d77c0b367e8695bf] [mlir][DialectConversion] 
Legalize all live argument conversions
   git bisect bad 4070f305f9a0c488d7177754d77c0b367e8695bf
   # bad: [3466e00716e12e32fdb100e3fcfca5c2b3e8d784] Reland "[Attr] support 
btf_type_tag attribute"
   git bisect bad 3466e00716e12e32fdb100e3fcfca5c2b3e8d784
   # good: [f64580f8d2ce5e1161857f9c89c2eee7a74c5ab8] [AArch64][GISel] Optimize 
8 and 16 bit variants of uaddo.
   git bisect good f64580f8d2ce5e1161857f9c89c2eee7a74c5ab8
   # first bad commit: [3466e00716e12e32fdb100e3fcfca5c2b3e8d784] Reland "[Attr] 
support btf_type_tag attribute"


Thanks. I will look at this problem immediately.



`cvise` spits out:

   $ cat efi.i
   typedef unsigned long efi_query_variable_info_t(int);
   typedef struct {
 struct {
   efi_query_variable_info_t __attribute__((regparm(0))) * 
query_variable_info;
 };
   } efi_runtime_services_t;
   efi_runtime_services_t efi_0;
   
   $ clang -m32 -O2 -c -o /dev/null efi.i
   

[...]
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-11-06 Thread Nathan Chancellor via Phabricator via cfe-commits
nathanchance added a comment.

I bisected a crash in the Linux kernel down to the reland commit (and it is not 
fixed as of 
https://github.com/llvm/llvm-project/commit/2249ecee8d9a6237f51485bd39f01ba031575987):

  $ git bisect log
  # bad: [bdaa181007a46d317a1665acb8234eddeee82815] [TwoAddressInstructionPass] 
Update existing physreg live intervals
  # good: [d4b1cf8f9c48a49ab808df15c4ab378276a07b82] [OpenMP] Build device 
runtimes for sm_86
  git bisect start 'bdaa181007a46d317a1665acb8234eddeee82815' 
'd4b1cf8f9c48a49ab808df15c4ab378276a07b82'
  # good: [f2703c3c3353031de8de8c465a59d31488b11fb3] [DAG] 
FoldConstantArithmetic - rename NumOps -> NumElts. NFC.
  git bisect good f2703c3c3353031de8de8c465a59d31488b11fb3
  # good: [c68183b81e5257186c9403cf91f8b958af7459bc] [gn build] Use `=` for of 
-fdebug-compilation-dir
  git bisect good c68183b81e5257186c9403cf91f8b958af7459bc
  # bad: [2d8ec3c61d3c2d47b303187bb882ca23544f6fc5] [libcxx] [test] Narrow down 
XFAILs regarding a MSVC mode specific bug to "windows-dll && msvc"
  git bisect bad 2d8ec3c61d3c2d47b303187bb882ca23544f6fc5
  # good: [97c899f3c5d9bbff2824b3252b21378bf96f3f3f] [mlir] Add callback to 
provide a pass pipeline to MlirOptMain
  git bisect good 97c899f3c5d9bbff2824b3252b21378bf96f3f3f
  # bad: [4070f305f9a0c488d7177754d77c0b367e8695bf] [mlir][DialectConversion] 
Legalize all live argument conversions
  git bisect bad 4070f305f9a0c488d7177754d77c0b367e8695bf
  # bad: [3466e00716e12e32fdb100e3fcfca5c2b3e8d784] Reland "[Attr] support 
btf_type_tag attribute"
  git bisect bad 3466e00716e12e32fdb100e3fcfca5c2b3e8d784
  # good: [f64580f8d2ce5e1161857f9c89c2eee7a74c5ab8] [AArch64][GISel] Optimize 
8 and 16 bit variants of uaddo.
  git bisect good f64580f8d2ce5e1161857f9c89c2eee7a74c5ab8
  # first bad commit: [3466e00716e12e32fdb100e3fcfca5c2b3e8d784] Reland "[Attr] 
support btf_type_tag attribute"

`cvise` spits out:

  $ cat efi.i
  typedef unsigned long efi_query_variable_info_t(int);
  typedef struct {
struct {
  efi_query_variable_info_t __attribute__((regparm(0))) * 
query_variable_info;
};
  } efi_runtime_services_t;
  efi_runtime_services_t efi_0;
  
  $ clang -m32 -O2 -c -o /dev/null efi.i
  
  $ clang -m32 -O2 -g -c -o /dev/null efi.i
  PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash 
backtrace, preprocessed source, and associated run script.
  Stack dump:
  0.  Program arguments: clang -m32 -O2 -g -c -o /dev/null efi.i
  1.   parser at end of file
   #0 0x02b31d13 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(/home/nathan/cbl/src/llvm-project/build/stage1/bin/clang-14+0x2b31d13)
   #1 0x02b2fb3e llvm::sys::RunSignalHandlers() 
(/home/nathan/cbl/src/llvm-project/build/stage1/bin/clang-14+0x2b2fb3e)
   #2 0x02ab8d13 (anonymous 
namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) 
CrashRecoveryContext.cpp:0:0
   #3 0x02ab8e8e CrashRecoverySignalHandler(int) 
CrashRecoveryContext.cpp:0:0
   #4 0x7fa9dd533870 __restore_rt sigaction.c:0:0
   #5 0x02eaa00e 
clang::CodeGen::CGDebugInfo::CreateType(clang::FunctionType const*, 
llvm::DIFile*, clang::TypeLoc) 
(/home/nathan/cbl/src/llvm-project/build/stage1/bin/clang-14+0x2eaa00e)
   #6 0x02ea4598 
clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*, 
clang::TypeLoc) 
(/home/nathan/cbl/src/llvm-project/build/stage1/bin/clang-14+0x2ea4598)
   #7 0x02ea7cc4 
clang::CodeGen::CGDebugInfo::CreatePointerLikeType(llvm::dwarf::Tag, 
clang::Type const*, clang::QualType, llvm::DIFile*, clang::TypeLoc) 
(/home/nathan/cbl/src/llvm-project/build/stage1/bin/clang-14+0x2ea7cc4)
   #8 0x02eb6558 
clang::CodeGen::CGDebugInfo::CreateTypeNode(clang::QualType, llvm::DIFile*, 
clang::TypeLoc) 
(/home/nathan/cbl/src/llvm-project/build/stage1/bin/clang-14+0x2eb6558)
   #9 0x02ea4598 
clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*, 
clang::TypeLoc) 
(/home/nathan/cbl/src/llvm-project/build/stage1/bin/clang-14+0x2ea4598)
  #10 0x02eaa610 
clang::CodeGen::CGDebugInfo::createFieldType(llvm::StringRef, clang::QualType, 
clang::SourceLocation, clang::AccessSpecifier, unsigned long, unsigned int, 
llvm::DIFile*, llvm::DIScope*, clang::RecordDecl const*, 
llvm::MDTupleTypedArrayWrapper, clang::TypeLoc) 
(/home/nathan/cbl/src/llvm-project/build/stage1/bin/clang-14+0x2eaa610)
  #11 0x02eab3c0 
clang::CodeGen::CGDebugInfo::CollectRecordNormalField(clang::FieldDecl const*, 
unsigned long, llvm::DIFile*, llvm::SmallVectorImpl&, 
llvm::DIType*, clang::RecordDecl const*) 
(/home/nathan/cbl/src/llvm-project/build/stage1/bin/clang-14+0x2eab3c0)
  #12 0x02eab90c 
clang::CodeGen::CGDebugInfo::CollectRecordFields(clang::RecordDecl const*, 
llvm::DIFile*, llvm::SmallVectorImpl&, llvm::DICompositeType*) 
(/home/nathan/cbl/src/llvm-project/build/stage1/bin/clang-14+0x2eab90c)
  #13 0x02eb111a 

Re: [PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-11-05 Thread Yonghong Song via cfe-commits



On 11/5/21 1:40 AM, Martin Storsjö via Phabricator wrote:

mstorsjo added a comment.

I went ahead and reverted this, as it caused crashes when compiling a number of 
projects. The most reduced testcase is this:

   $ cat reduced.c
   void a(*);
   void a() {}
   $ clang -c reduced.c -O2 -g

A full case (which reduces into this) is this, 
https://martin.st/temp/iconv-preproc.c , built with `clang -target 
i686-w64-mingw32 -w -c -O2 -g iconv-preproc.c`.



Martin, thanks for reporting. Let me debug this.



Repository:
   rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-11-05 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

I went ahead and reverted this, as it caused crashes when compiling a number of 
projects. The most reduced testcase is this:

  $ cat reduced.c 
  void a(*);
  void a() {}
  $ clang -c reduced.c -O2 -g

A full case (which reduces into this) is this, 
https://martin.st/temp/iconv-preproc.c, built with `clang -target 
i686-w64-mingw32 -w -c -O2 -g iconv-preproc.c`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-11-04 Thread Yonghong Song via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeb0fa8bfa356: [Clang][Attr] Support btf_type_tag attribute 
(authored by yonghong-song).

Changed prior to commit:
  https://reviews.llvm.org/D99?vs=384843=384862#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/Sema/attr-btf_type_tag.c

Index: clang/test/Sema/attr-btf_type_tag.c
===
--- /dev/null
+++ clang/test/Sema/attr-btf_type_tag.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -x c -triple x86_64-pc-linux-gnu -dwarf-version=4 -fsyntax-only -verify %s
+
+#define __tag1 __attribute__((btf_type_tag("tag1")))
+#define __tag2 __attribute__((btf_type_tag("tag2")))
+#define __tag3 __attribute__((btf_type_tag("tag3")))
+#define __tag4 __attribute__((btf_type_tag("tag4")))
+#define __tag5 __attribute__((btf_type_tag("tag5")))
+#define __tag6 __attribute__((btf_type_tag("tag6")))
+
+int __attribute__((btf_type_tag("tag1", "tag2"))) *invalid1; // expected-error {{'btf_type_tag' attribute takes one argument}}
+int __attribute__((btf_type_tag(2))) *invalid2; // expected-error {{'btf_type_tag' attribute requires a string}}
+
+int * __tag1 __tag2 * __tag3 __tag4 * __tag5 __tag6 *g;
+
+typedef void __fn_t(int);
+typedef __fn_t __tag1 __tag2 * __tag3 __tag4 *__fn2_t;
+struct t {
+  int __tag1 * __tag2 * __tag3 *a;
+  int __tag1 __tag2 __tag3 *b;
+  __fn2_t c;
+  long d;
+};
+int __tag4 * __tag5 * __tag6 *foo1(struct t __tag1 * __tag2 * __tag3 *a1) {
+  return (int __tag4 * __tag5 * __tag6 *)a1[0][0]->d;
+}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -5900,6 +5900,9 @@
 void VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
   Visit(TL.getUnqualifiedLoc());
 }
+// Allow to fill pointee's type locations, e.g.,
+//   int __attr * __attr * __attr *p;
+void VisitPointerTypeLoc(PointerTypeLoc TL) { Visit(TL.getNextTypeLoc()); }
 void VisitTypedefTypeLoc(TypedefTypeLoc TL) {
   TL.setNameLoc(DS.getTypeSpecTypeLoc());
 }
@@ -6500,6 +6503,34 @@
   return BuildAddressSpaceAttr(T, ASIdx, AddrSpace, AttrLoc);
 }
 
+static void HandleBTFTypeTagAttribute(QualType , const ParsedAttr ,
+  TypeProcessingState ) {
+  Sema  = State.getSema();
+
+  // Check the number of attribute arguments.
+  if (Attr.getNumArgs() != 1) {
+S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
+<< Attr << 1;
+Attr.setInvalid();
+return;
+  }
+
+  // Ensure the argument is a string.
+  auto *StrLiteral = dyn_cast(Attr.getArgAsExpr(0));
+  if (!StrLiteral) {
+S.Diag(Attr.getLoc(), diag::err_attribute_argument_type)
+<< Attr << AANT_ArgumentString;
+Attr.setInvalid();
+return;
+  }
+
+  ASTContext  = S.Context;
+  StringRef BTFTypeTag = StrLiteral->getString();
+  Type = State.getAttributedType(
+  ::new (Ctx) BTFTypeTagAttr(Ctx, Attr, BTFTypeTag), Type, Type);
+  return;
+}
+
 /// HandleAddressSpaceTypeAttribute - Process an address_space attribute on the
 /// specified type.  The attribute contains 1 argument, the id of the address
 /// space for the type.
@@ -8129,6 +8160,11 @@
 case ParsedAttr::IgnoredAttribute:
   break;
 
+case ParsedAttr::AT_BTFTypeTag:
+  HandleBTFTypeTagAttribute(type, attr, state);
+  attr.setUsedAsTypeAttr();
+  break;
+
 case ParsedAttr::AT_MayAlias:
   // FIXME: This attribute needs to actually be handled, but if we ignore
   // it it breaks large amounts of Linux software.
Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1746,6 +1746,9 @@
   case attr::ArmMveStrictPolymorphism:
 OS << "__clang_arm_mve_strict_polymorphism";
 break;
+  case attr::BTFTypeTag:
+OS << "btf_type_tag";
+break;
   }
   OS << "))";
 }
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -2023,6 +2023,23 @@
   }];
 }
 
+def BTFTypeTagDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+Clang supports the ``__attribute__((btf_type_tag("ARGUMENT")))`` attribute for
+all targets. It only has effect when ``-g`` is specified on the command line and
+is currently silently ignored when not applied to a pointer type (note: this
+scenario may be diagnosed in the future).
+
+The ``ARGUMENT`` string will be preserved in IR 

[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-11-04 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song updated this revision to Diff 384843.
yonghong-song added a comment.

- Change TypeLoc.isNull() check to !TypeLoc


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/AST/TypePrinter.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/attr-btf_type_tag-func.c
  clang/test/CodeGen/attr-btf_type_tag-typedef-field.c
  clang/test/CodeGen/attr-btf_type_tag-var.c
  clang/test/Sema/attr-btf_type_tag.c
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/IR/DIBuilder.cpp
  llvm/test/Bitcode/attr-btf_type_tag.ll
  llvm/test/DebugInfo/attr-btf_type_tag.ll

Index: llvm/test/DebugInfo/attr-btf_type_tag.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/attr-btf_type_tag.ll
@@ -0,0 +1,62 @@
+; REQUIRES: x86-registered-target
+; RUN: llc -filetype=obj -o %t %s
+; RUN: llvm-dwarfdump -debug-info %t | FileCheck %s
+; Source:
+;   #define __tag1 __attribute__((btf_type_tag("tag1")))
+;   #define __tag2 __attribute__((btf_type_tag("tag2")))
+;
+;   int * __tag1 * __tag2 *g;
+; Compilation flag:
+;   clang -target x86_64 -g -S -emit-llvm t.c
+
+@g = dso_local global i32*** null, align 8, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!13, !14, !15, !16, !17}
+!llvm.ident = !{!18}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 4, type: !5, 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 2c240a5eefae1a945dfd36cdaa0c677eca90dd82)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "t.c", directory: "/home/yhs/work/tests/llvm/btf_tag_type")
+!4 = !{!0}
+!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64, annotations: !11)
+!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64, annotations: !9)
+!7 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)
+!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!9 = !{!10}
+!10 = !{!"btf_type_tag", !"tag1"}
+!11 = !{!12}
+!12 = !{!"btf_type_tag", !"tag2"}
+
+; CHECK:  DW_TAG_variable
+; CHECK-NEXT:   DW_AT_name  ("g")
+; CHECK-NEXT:   DW_AT_type  (0x[[T1:[0-9]+]] "int ***")
+
+; CHECK:  0x[[T1]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[T2:[0-9]+]] "int **")
+
+; CHECK:DW_TAG_LLVM_annotation
+; CHECK-NEXT: DW_AT_name("btf_type_tag")
+; CHECK-NEXT: DW_AT_const_value ("tag2")
+
+; CHECK:NULL
+
+; CHECK:  0x[[T2]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[T3:[0-9]+]] "int *")
+
+; CHECK:DW_TAG_LLVM_annotation
+; CHECK-NEXT: DW_AT_name("btf_type_tag")
+; CHECK-NEXT: DW_AT_const_value ("tag1")
+
+; CHECK:NULL
+
+; CHECK:  0x[[T3]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[#]] "int")
+
+!13 = !{i32 7, !"Dwarf Version", i32 4}
+!14 = !{i32 2, !"Debug Info Version", i32 3}
+!15 = !{i32 1, !"wchar_size", i32 4}
+!16 = !{i32 7, !"uwtable", i32 1}
+!17 = !{i32 7, !"frame-pointer", i32 2}
+!18 = !{!"clang version 14.0.0 (https://github.com/llvm/llvm-project.git 2c240a5eefae1a945dfd36cdaa0c677eca90dd82)"}
Index: llvm/test/Bitcode/attr-btf_type_tag.ll
===
--- /dev/null
+++ llvm/test/Bitcode/attr-btf_type_tag.ll
@@ -0,0 +1,36 @@
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
+;
+; Source:
+;   #define __tag1 __attribute__((btf_type_tag("tag1")))
+;   int __tag1 *g;
+; Compilation flag:
+;   clang -S -g -emit-llvm test.c
+
+@g = dso_local global i32* null, align 8, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!9, !10, !11, !12, !13}
+!llvm.ident = !{!14}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 2, type: !5, 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 248122328bfefe82608a2e110af3a3ff04279ddf)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm/btf_tag_type")
+!4 = !{!0}
+!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64, annotations: !7)
+!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!7 = !{!8}
+!8 = !{!"btf_type_tag", !"tag1"}
+
+; CHECK:   distinct !DIGlobalVariable(name: "g", scope: 

[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-11-04 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1426
+  TypeLoc RetTL;
+  if (!TL.isNull()) {
+if (auto FTL = TL.getAs())

dblaikie wrote:
> I'm /guessing/ this can be rewritten as:
> ```
> if (TL)
> ```
> ? (similarly elsewhere in this patch)
Yes. Indeed. Thanks for the suggestion! Will make changes in the next revision.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1440-1441
+bool DoneWithTL = false;
+if (!TL.isNull()) {
+  if (auto FTL = TL.getAs()) {
+DoneWithTL = true;

dblaikie wrote:
> Is this null check necessary, or does "getAs" return null if the underlying 
> value is null already anyway? (oh, and this would apply above as well)
Yes. null check is necessary. Otherwise, we will get an assertion error like
```
clang: /home/yhs/work/llvm-project/clang/include/clang/AST/Type.h:689: const 
clang::ExtQualsTypeCommonBase* clang::QualType::getCommonPtr() const: Assertion 
`!isNull() && "Cannot retrieve 
a NULL type pointer"' failed.   


PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash 
backtrace, preprocessed source, and associated run script.  
 
Stack dump: 


0.  Program arguments: clang -g -D__TARGET_ARCH_x86 -mlittle-endian 
-I/home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/include 
-I/home/yhs/work/bpf-next/tools/testing/selftest
s/bpf -I/home/yhs/work/bpf-next/tools/include/uapi 
-I/home/yhs/work/bpf-next/tools/testing/selftests/usr/include -idirafter 
/home/yhs/work/llvm-project/llvm/build.cur/install/lib/clang/14.
0.0/include -idirafter /usr/local/include -idirafter /usr/include 
-Wno-compare-distinct-pointer-types -DENABLE_ATOMICS_TESTS -O2 -target bpf -c 
progs/btf_dump_test_case_multidim.c -o /home
/yhs/work/bpf-next/tools/testing/selftests/bpf/btf_dump_test_case_multidim.o 
-mcpu=v3
   
1.   parser at end of file 


2.  progs/btf_dump_test_case_multidim.c:32:5: LLVM IR generation of 
declaration 'f' 

3.  progs/btf_dump_test_case_multidim.c:32:5: Generating code for 
declaration 'f' 
  
 #0 0x01e9e03f PrintStackTraceSignalHandler(void*) Signals.cpp:0:0  


 #1 0x01e9be7c llvm::sys::CleanupOnSignal(unsigned long) 
(/home/yhs/work/llvm-project/llvm/build.cur/install/bin/clang-14+0x1e9be7c) 
   
 #2 0x01dea448 CrashRecoverySignalHandler(int) 
CrashRecoveryContext.cpp:0:0
 
 #3 0x7f7b08be4c20 __restore_rt sigaction.c:0:0 


 #4 0x7f7b078dc37f raise (/lib64/libc.so.6+0x3737f) 


 #5 0x7f7b078c6db5 abort (/lib64/libc.so.6+0x21db5) 


 #6 0x7f7b078c6c89 _nl_load_domain.cold.0 loadmsgcat.c:0:0  


 #7 0x7f7b078d4a76 .annobin___GI___assert_fail.end assert.c:0:0 


 #8 0x02193ba3 
(/home/yhs/work/llvm-project/llvm/build.cur/install/bin/clang-14+0x2193ba3) 

 
 #9 0x021b4981 
clang::CodeGen::CGDebugInfo::CreateType(clang::FunctionType const*, 
llvm::DIFile*, clang::TypeLoc) 
(/home/yhs/work/llvm-project/llvm/build.cur/install/bin/clang-14+0
x21b4981)   

[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-11-04 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.

Seems unfortunate that attributes on types are only available through TypeLocs 
rather than through sugar (like if we used a typedef it'd be visible in the 
type sugar, but not if it's written on the type usage itself) - but that's 
above my domain knowledge here & I'll take it there are some good reasons for 
that to be the way it is.




Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1426
+  TypeLoc RetTL;
+  if (!TL.isNull()) {
+if (auto FTL = TL.getAs())

I'm /guessing/ this can be rewritten as:
```
if (TL)
```
? (similarly elsewhere in this patch)



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1440-1441
+bool DoneWithTL = false;
+if (!TL.isNull()) {
+  if (auto FTL = TL.getAs()) {
+DoneWithTL = true;

Is this null check necessary, or does "getAs" return null if the underlying 
value is null already anyway? (oh, and this would apply above as well)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-11-04 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

In D99#3108092 , @yonghong-song 
wrote:

>> That sounds reasonable to me, but one possibility would be to change 
>> createType() and getOrCreateType() to take a TypeSourceInfo * rather than a 
>> QualType (because you can go from the TypeSourceInfo * back to the QualType 
>> by calling getType() on it). However, that could also be a heavier lift due 
>> to the number of call sites.
>
> I think this probably hard to do. If I understand correctly, TypeSourceInfo * 
> is available for declarations. But majority of getOrCreateType() does not 
> have TypeSourceInfo *. For example for "int ***p", "int ***" does have a 
> corresponding TypeSourceInfo *, but "int **" or "int *" does not.  Unless you 
> mean we can get QualType from TypeLoc which is actually true. But then the 
> problem is currently I only handle limited cases, certainly all C++ 
> template/Class etc. are not covered, so we cannot really remove QualType as 
> in many cases TypeLoc.isNull() is true.

Yeah, that's why I was thinking this was too heavy of a lift. So this LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-11-04 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

> That sounds reasonable to me, but one possibility would be to change 
> createType() and getOrCreateType() to take a TypeSourceInfo * rather than a 
> QualType (because you can go from the TypeSourceInfo * back to the QualType 
> by calling getType() on it). However, that could also be a heavier lift due 
> to the number of call sites.

I think this probably hard to do. If I understand correctly, TypeSourceInfo * 
is available for declarations. But majority of getOrCreateType() does not have 
TypeSourceInfo *. For example for "int ***p", "int ***" does have a 
corresponding TypeSourceInfo *, but "int **" or "int *" does not.

Unless you mean we can get QualType from TypeLoc which is actually true. But 
then the problem is currently I only handle limited cases, certainly all C++ 
template/Class etc. are not covered, so we cannot really remove QualType as in 
many cases TypeLoc.isNull() is true.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-11-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D99#3104804 , @yonghong-song 
wrote:

> @aaron.ballman I checked the source. Looks like we can easily get TypeLoc 
> from TypeSourceInfo, but not from TypeSourceInfo to TypeLoc. But We need 
> TypeLoc so we can get attr information and also traverse TypeLoc's.. We might 
> be able to pass TypeSourceInfo in a few functions e.g., createFieldType(), 
> but we still need to do TSI->getTypeLoc() and pass TypeLoc to other functions 
> like getOrCreateType(), createType() etc. So I am inclined to just use 
> TypeLoc.
>
> @dblaikie Based on the discussion so far, I suspect we might have to use 
> TypeLoc. Please let me know what you think.

That sounds reasonable to me, but one possibility would be to change 
`createType()` and `getOrCreateType()` to take a `TypeSourceInfo *` rather than 
a `QualType` (because you can go from the `TypeSourceInfo *` back to the 
`QualType` by calling `getType()` on it). However, that could also be a heavier 
lift due to the number of call sites.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-11-02 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

@aaron.ballman I checked the source. Looks like we can easily get TypeLoc from 
TypeSourceInfo, but not from TypeSourceInfo to TypeLoc. But We need TypeLoc so 
we can get attr information and also traverse TypeLoc's.. We might be able to 
pass TypeSourceInfo in a few functions e.g., createFieldType(), but we still 
need to do TSI->getTypeLoc() and pass TypeLoc to other functions like 
getOrCreateType(), createType() etc. So I am inclined to just use TypeLoc.

@dblaikie Based on the discussion so far, I suspect we might have to use 
TypeLoc. Please let me know what you think.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-11-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D99#3101484 , @yonghong-song 
wrote:

> Just to be sure my understanding is correct. Given an AttributedType node, we 
> do have a way to get the corresponding Attr, is it right? @aaron.ballman

Oh yeah, now I remember what the problem is here! `Type *` is the abstract 
representation of type information in Clang. e.g. it represents an `int` in 
general, not a specific use of `int`. For the specific use, you need to ask the 
declaration for its particular `TypeSourceInfo *` object. So `AttributedType` 
tracks what KIND of attribute it was, but not the actual attribute itself, 
which means there's no way to go from an `AttributedType *` to an `Attr *` 
without first going through a `TypeSourceInfo *`. You can get one of those from 
various declarations (`DeclaratorDecl` and `TypedefNameDecl`), but the 
functions where you need to get to the attribute instance from don't always 
have the declaration handy (it'd be good to check if there are any interfaces 
that do have the decl handy so we can skip passing the extra argument there). 
So we need to pass something in some places, either a `TypeSourceInfo *` or a 
`TypeLoc`. A `TypeLoc` is two pointers wide, so it might make sense to pass the 
`TypeSourceInfo *` instead, but I don't have strong opinions there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-11-01 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

Just to be sure my understanding is correct. Given an AttributedType node, we 
do have a way to get the corresponding Attr, is it right? @aaron.ballman


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-11-01 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D99#3099988 , @aaron.ballman 
wrote:

> In D99#3097692 , @dblaikie 
> wrote:
>
>> In D99#3096124 , 
>> @aaron.ballman wrote:
>>
>>> In D99#3095623 , 
>>> @yonghong-song wrote:
>>>
> Ah, yeah, I see what you mean - that does seem sort of unfortunate. Is it 
> possible these attributes could only appear on typedefs and they'd be 
> more readily carried through that without needing extra typeloc tracking? 
> (sorry for not having read back through the rest of the review - which 
> may've started there and ended up here as a more general form of the 
> attribute?)

 For the question, "is it possible these attributes could only appear on 
 typedefs?" The answer is "not really possible". We are targeting existing 
 linux kernel where existing type attributes (__user, __rcu, ...) have been 
 used in places other than typedef quite extensively (e.g., function 
 argument type, function return type, field type, etc.).

 In one of my earlier prototypes, I put the tag string itself in 
 AttributedType and with this we can avoid TypeLoc, but I understand this 
 is not conventional usage and that is why we do through TypeLoc mechanism. 
 @aaron.ballman can further comment on this.
>>>
>>> FWIW, I made that request because AttributedTypeLoc stores the Attr * for 
>>> the attributed type, so we can get the attribute argument information from 
>>> that rather than having to duplicate it within a new TypeLoc object.
>>
>> So could the debug info code be done with AttributedType (I guess currently 
>> CGDebugInfo skips over those - but we could not skip over them and check if 
>> it's one of these attributes, otherwise skip) rather than passing around the 
>> extra TypeLoc?
>
> That's my hope, but I wasn't certain if there were type modifications 
> happening where we need to calculate a `TypeLoc` that's different from what 
> we would get out of the type itself. I would expect that doesn't happen 
> during CodeGen (seems awfully late to be changing types), but wasn't 100% 
> sure.

Hmm - not sure I really follow. Is there a greater risk of this than with other 
types we're emitting/lrelying entirely on types and not TypeLocs already? Any 
way we can validate whether this is an issue/is necessary to handle?

Otherwise I'd be inclined to go with the pure Type based solution, maybe leave 
a "watch out for bugs related to type changes" comment somewhere in case bugs 
do come up in the future?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-11-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D99#3097692 , @dblaikie wrote:

> In D99#3096124 , @aaron.ballman 
> wrote:
>
>> In D99#3095623 , 
>> @yonghong-song wrote:
>>
 Ah, yeah, I see what you mean - that does seem sort of unfortunate. Is it 
 possible these attributes could only appear on typedefs and they'd be more 
 readily carried through that without needing extra typeloc tracking? 
 (sorry for not having read back through the rest of the review - which 
 may've started there and ended up here as a more general form of the 
 attribute?)
>>>
>>> For the question, "is it possible these attributes could only appear on 
>>> typedefs?" The answer is "not really possible". We are targeting existing 
>>> linux kernel where existing type attributes (__user, __rcu, ...) have been 
>>> used in places other than typedef quite extensively (e.g., function 
>>> argument type, function return type, field type, etc.).
>>>
>>> In one of my earlier prototypes, I put the tag string itself in 
>>> AttributedType and with this we can avoid TypeLoc, but I understand this is 
>>> not conventional usage and that is why we do through TypeLoc mechanism. 
>>> @aaron.ballman can further comment on this.
>>
>> FWIW, I made that request because AttributedTypeLoc stores the Attr * for 
>> the attributed type, so we can get the attribute argument information from 
>> that rather than having to duplicate it within a new TypeLoc object.
>
> So could the debug info code be done with AttributedType (I guess currently 
> CGDebugInfo skips over those - but we could not skip over them and check if 
> it's one of these attributes, otherwise skip) rather than passing around the 
> extra TypeLoc?

That's my hope, but I wasn't certain if there were type modifications happening 
where we need to calculate a `TypeLoc` that's different from what we would get 
out of the type itself. I would expect that doesn't happen during CodeGen 
(seems awfully late to be changing types), but wasn't 100% sure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-10-29 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D99#3096124 , @aaron.ballman 
wrote:

> In D99#3095623 , @yonghong-song 
> wrote:
>
>>> Ah, yeah, I see what you mean - that does seem sort of unfortunate. Is it 
>>> possible these attributes could only appear on typedefs and they'd be more 
>>> readily carried through that without needing extra typeloc tracking? (sorry 
>>> for not having read back through the rest of the review - which may've 
>>> started there and ended up here as a more general form of the attribute?)
>>
>> For the question, "is it possible these attributes could only appear on 
>> typedefs?" The answer is "not really possible". We are targeting existing 
>> linux kernel where existing type attributes (__user, __rcu, ...) have been 
>> used in places other than typedef quite extensively (e.g., function argument 
>> type, function return type, field type, etc.).
>>
>> In one of my earlier prototypes, I put the tag string itself in 
>> AttributedType and with this we can avoid TypeLoc, but I understand this is 
>> not conventional usage and that is why we do through TypeLoc mechanism. 
>> @aaron.ballman can further comment on this.
>
> FWIW, I made that request because AttributedTypeLoc stores the Attr * for the 
> attributed type, so we can get the attribute argument information from that 
> rather than having to duplicate it within a new TypeLoc object.

So could the debug info code be done with AttributedType (I guess currently 
CGDebugInfo skips over those - but we could not skip over them and check if 
it's one of these attributes, otherwise skip) rather than passing around the 
extra TypeLoc?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-10-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D99#3095623 , @yonghong-song 
wrote:

>> Ah, yeah, I see what you mean - that does seem sort of unfortunate. Is it 
>> possible these attributes could only appear on typedefs and they'd be more 
>> readily carried through that without needing extra typeloc tracking? (sorry 
>> for not having read back through the rest of the review - which may've 
>> started there and ended up here as a more general form of the attribute?)
>
> For the question, "is it possible these attributes could only appear on 
> typedefs?" The answer is "not really possible". We are targeting existing 
> linux kernel where existing type attributes (__user, __rcu, ...) have been 
> used in places other than typedef quite extensively (e.g., function argument 
> type, function return type, field type, etc.).
>
> In one of my earlier prototypes, I put the tag string itself in 
> AttributedType and with this we can avoid TypeLoc, but I understand this is 
> not conventional usage and that is why we do through TypeLoc mechanism. 
> @aaron.ballman can further comment on this.

FWIW, I made that request because AttributedTypeLoc stores the Attr * for the 
attributed type, so we can get the attribute argument information from that 
rather than having to duplicate it within a new TypeLoc object.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-10-29 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

> Ah, yeah, I see what you mean - that does seem sort of unfortunate. Is it 
> possible these attributes could only appear on typedefs and they'd be more 
> readily carried through that without needing extra typeloc tracking? (sorry 
> for not having read back through the rest of the review - which may've 
> started there and ended up here as a more general form of the attribute?)

For the question, "is it possible these attributes could only appear on 
typedefs?" The answer is "not really possible". We are targeting existing linux 
kernel where existing type attributes (__user, __rcu, ...) have been used in 
places other than typedef quite extensively (e.g., function argument type, 
function return type, field type, etc.).

In one of my earlier prototypes, I put the tag string itself in AttributedType 
and with this we can avoid TypeLoc, but I understand this is not conventional 
usage and that is why we do through TypeLoc mechanism. @aaron.ballman can 
further comment on this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-10-28 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D99#3093448 , @aaron.ballman 
wrote:

> Attribute bits look good to me, but I'd appreciate if @dblaikie could weigh 
> in on whether he thinks the CodeGen changes are fine. My concern there is 
> around whether the changes to function signatures to accept a `TypeLoc` are 
> reasonable or not.

Thanks for pulling me in here - appreciate all the reviewing you've been doing 
on this whole series & glad to be pulled in anywhere you think's helpful.

Ah, yeah, I see what you mean - that does seem sort of unfortunate. Is it 
possible these attributes could only appear on typedefs and they'd be more 
readily carried through that without needing extra typeloc tracking? (sorry for 
not having read back through the rest of the review - which may've started 
there and ended up here as a more general form of the attribute?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-10-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Attribute bits look good to me, but I'd appreciate if @dblaikie could weigh in 
on whether he thinks the CodeGen changes are fine. My concern there is around 
whether the changes to function signatures to accept a `TypeLoc` are reasonable 
or not.




Comment at: clang/include/clang/Basic/AttrDocs.td:2031
+all targets. It only has effect when ``-g`` is specified on the command line 
and
+may only be specified on a pointer type.
+

This makes it a bit more clear what the current behavior is and that we might 
change that behavior in the future,


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-10-27 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

Agreed. If after semantic analysis for a declaration we can check declaration's 
typeloc chain again, we might be able to give proper warnings. I am happy to 
implement this as a followup as you suggested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-10-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:6526
+  }
+
+  ASTContext  = S.Context;

yonghong-song wrote:
> aaron.ballman wrote:
> > Should you also validate that the type is a pointer type?
> Looks like we cannot do this. For example,
>int __attribute__((btf_type_tag("tag"))) *p;
> 
> When we reach `HandleBTFTypeTagAttribute`, we actually have `Type` as `int`.
> We don't have information for its `parent` type.
> 
> During code generation, we have
>pointer_type
>   attributed_type
>  builtin_int type
> at that point, we can check pointer type's next typeloc's to decide whether 
> it has attributed_type or not.
Ugh, GNU-style attributes are particularly awful. My initial inclination was 
that's the exact sort of situation we want to ignore because the type attribute 
should appertain to the type it's specified on (int, not int *), but GNU-style 
attributes "slide" to whatever the compiler thinks makes the most sense, so 
they're unpredictable for these kinds of uses.

However, the rule of thumb in Clang is that ignoring the attribute should come 
with a diagnostic so the user knows it's being ignored, otherwise they have a 
harder time debugging problems when they've misused the attribute. Currently, I 
think this will give no diagnostics when ignoring the attribute in way too many 
situations (attaching it to a struct declaration, attaching it to a 
non-pointer, etc).

We could perhaps change `GetDeclSpecTypeForDeclarator()` to add additional 
checking logic after the call to `distributeTypeAttrsFromDeclarator()`. 
However, we don't currently have any type attributes that need this kind of 
special handling and so that could perhaps wait for a follow-up.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-10-26 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song updated this revision to Diff 382518.
yonghong-song added a comment.

- fix various clang-format and coding style issue suggested by @aaron.ballman


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/AST/TypePrinter.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/attr-btf_type_tag-func.c
  clang/test/CodeGen/attr-btf_type_tag-typedef-field.c
  clang/test/CodeGen/attr-btf_type_tag-var.c
  clang/test/Sema/attr-btf_type_tag.c
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/IR/DIBuilder.cpp
  llvm/test/Bitcode/attr-btf_type_tag.ll
  llvm/test/DebugInfo/attr-btf_type_tag.ll

Index: llvm/test/DebugInfo/attr-btf_type_tag.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/attr-btf_type_tag.ll
@@ -0,0 +1,62 @@
+; REQUIRES: x86-registered-target
+; RUN: llc -filetype=obj -o %t %s
+; RUN: llvm-dwarfdump -debug-info %t | FileCheck %s
+; Source:
+;   #define __tag1 __attribute__((btf_type_tag("tag1")))
+;   #define __tag2 __attribute__((btf_type_tag("tag2")))
+;
+;   int * __tag1 * __tag2 *g;
+; Compilation flag:
+;   clang -target x86_64 -g -S -emit-llvm t.c
+
+@g = dso_local global i32*** null, align 8, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!13, !14, !15, !16, !17}
+!llvm.ident = !{!18}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 4, type: !5, 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 2c240a5eefae1a945dfd36cdaa0c677eca90dd82)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "t.c", directory: "/home/yhs/work/tests/llvm/btf_tag_type")
+!4 = !{!0}
+!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64, annotations: !11)
+!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64, annotations: !9)
+!7 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)
+!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!9 = !{!10}
+!10 = !{!"btf_type_tag", !"tag1"}
+!11 = !{!12}
+!12 = !{!"btf_type_tag", !"tag2"}
+
+; CHECK:  DW_TAG_variable
+; CHECK-NEXT:   DW_AT_name  ("g")
+; CHECK-NEXT:   DW_AT_type  (0x[[T1:[0-9]+]] "int ***")
+
+; CHECK:  0x[[T1]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[T2:[0-9]+]] "int **")
+
+; CHECK:DW_TAG_LLVM_annotation
+; CHECK-NEXT: DW_AT_name("btf_type_tag")
+; CHECK-NEXT: DW_AT_const_value ("tag2")
+
+; CHECK:NULL
+
+; CHECK:  0x[[T2]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[T3:[0-9]+]] "int *")
+
+; CHECK:DW_TAG_LLVM_annotation
+; CHECK-NEXT: DW_AT_name("btf_type_tag")
+; CHECK-NEXT: DW_AT_const_value ("tag1")
+
+; CHECK:NULL
+
+; CHECK:  0x[[T3]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[#]] "int")
+
+!13 = !{i32 7, !"Dwarf Version", i32 4}
+!14 = !{i32 2, !"Debug Info Version", i32 3}
+!15 = !{i32 1, !"wchar_size", i32 4}
+!16 = !{i32 7, !"uwtable", i32 1}
+!17 = !{i32 7, !"frame-pointer", i32 2}
+!18 = !{!"clang version 14.0.0 (https://github.com/llvm/llvm-project.git 2c240a5eefae1a945dfd36cdaa0c677eca90dd82)"}
Index: llvm/test/Bitcode/attr-btf_type_tag.ll
===
--- /dev/null
+++ llvm/test/Bitcode/attr-btf_type_tag.ll
@@ -0,0 +1,36 @@
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
+;
+; Source:
+;   #define __tag1 __attribute__((btf_type_tag("tag1")))
+;   int __tag1 *g;
+; Compilation flag:
+;   clang -S -g -emit-llvm test.c
+
+@g = dso_local global i32* null, align 8, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!9, !10, !11, !12, !13}
+!llvm.ident = !{!14}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 2, type: !5, 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 248122328bfefe82608a2e110af3a3ff04279ddf)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm/btf_tag_type")
+!4 = !{!0}
+!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64, annotations: !7)
+!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!7 = !{!8}
+!8 = !{!"btf_type_tag", !"tag1"}
+
+; CHECK:   distinct 

[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-10-26 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

All other comments make sense. Will fix them in the next revision.




Comment at: clang/lib/Sema/SemaType.cpp:6526
+  }
+
+  ASTContext  = S.Context;

aaron.ballman wrote:
> Should you also validate that the type is a pointer type?
Looks like we cannot do this. For example,
   int __attribute__((btf_type_tag("tag"))) *p;

When we reach `HandleBTFTypeTagAttribute`, we actually have `Type` as `int`.
We don't have information for its `parent` type.

During code generation, we have
   pointer_type
  attributed_type
 builtin_int type
at that point, we can check pointer type's next typeloc's to decide whether it 
has attributed_type or not.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-10-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added reviewers: rsmith, dblaikie.
aaron.ballman added a comment.

Adding some additional reviewers who may have more opinions about the changes 
in CodeGen.




Comment at: clang/include/clang/Basic/AttrDocs.td:2029-2034
+Clang supports the ``__attribute__((btf_type_tag("ARGUMENT")))`` attribute for
+all targets. If -g is specified, for variable declaration type, function return
+type, function argument type, or typedef underlying type, if these types
+are pointer types, the ``ARGUMENT`` info will be preserved in IR and be emitted
+to dwarf. FOR BPF trgets, the ``ARGUMENT`` info will be eimitted to .BTF ELF
+section too.





Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:941-947
+if (auto MTL = TL.getAs()) {
+  TL = MTL.getInnerLoc();
+} else if (auto ATL = TL.getAs()) {
+  TL = ATL.getModifiedLoc();
+} else {
+  break;
+}

Phab's diff view is not helpful here -- removing the curly braces around 
single-line statements per our usual coding standards.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1337
+  TypeLoc TL;
+  if (auto TSI = Ty->getDecl()->getTypeSourceInfo())
+TL = TSI->getTypeLoc();





Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1447-1448
+  TypeLoc ParamTL;
+  if (auto Param = FTL.getParam(Idx)) {
+if (auto TSI = Param->getTypeSourceInfo())
+  ParamTL = TSI->getTypeLoc();

Can you spell out the types here?



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1646
+TypeLoc TL;
+if (auto TSI = field->getTypeSourceInfo())
+  TL = TSI->getTypeLoc();





Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:4061
+  if (const auto *FD = dyn_cast(D)) {
+if (auto TSI = FD->getTypeSourceInfo())
+  TL = TSI->getTypeLoc();





Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:4468
+TypeLoc TL;
+if (auto TSI = VD->getTypeSourceInfo())
+  TL = TSI->getTypeLoc();





Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:5196
+TypeLoc TL;
+if (auto TSI = D->getTypeSourceInfo())
+  TL = TSI->getTypeLoc();





Comment at: clang/lib/Sema/SemaType.cpp:6526
+  }
+
+  ASTContext  = S.Context;

Should you also validate that the type is a pointer type?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-10-25 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song updated this revision to Diff 382143.
yonghong-song added a comment.

- fix clang-format warnings


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/AST/TypePrinter.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/attr-btf_type_tag-func.c
  clang/test/CodeGen/attr-btf_type_tag-typedef-field.c
  clang/test/CodeGen/attr-btf_type_tag-var.c
  clang/test/Sema/attr-btf_type_tag.c
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/IR/DIBuilder.cpp
  llvm/test/Bitcode/attr-btf_type_tag.ll
  llvm/test/DebugInfo/attr-btf_type_tag.ll

Index: llvm/test/DebugInfo/attr-btf_type_tag.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/attr-btf_type_tag.ll
@@ -0,0 +1,62 @@
+; REQUIRES: x86-registered-target
+; RUN: llc -filetype=obj -o %t %s
+; RUN: llvm-dwarfdump -debug-info %t | FileCheck %s
+; Source:
+;   #define __tag1 __attribute__((btf_type_tag("tag1")))
+;   #define __tag2 __attribute__((btf_type_tag("tag2")))
+;
+;   int * __tag1 * __tag2 *g;
+; Compilation flag:
+;   clang -target x86_64 -g -S -emit-llvm t.c
+
+@g = dso_local global i32*** null, align 8, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!13, !14, !15, !16, !17}
+!llvm.ident = !{!18}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 4, type: !5, 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 2c240a5eefae1a945dfd36cdaa0c677eca90dd82)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "t.c", directory: "/home/yhs/work/tests/llvm/btf_tag_type")
+!4 = !{!0}
+!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64, annotations: !11)
+!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64, annotations: !9)
+!7 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)
+!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!9 = !{!10}
+!10 = !{!"btf_type_tag", !"tag1"}
+!11 = !{!12}
+!12 = !{!"btf_type_tag", !"tag2"}
+
+; CHECK:  DW_TAG_variable
+; CHECK-NEXT:   DW_AT_name  ("g")
+; CHECK-NEXT:   DW_AT_type  (0x[[T1:[0-9]+]] "int ***")
+
+; CHECK:  0x[[T1]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[T2:[0-9]+]] "int **")
+
+; CHECK:DW_TAG_LLVM_annotation
+; CHECK-NEXT: DW_AT_name("btf_type_tag")
+; CHECK-NEXT: DW_AT_const_value ("tag2")
+
+; CHECK:NULL
+
+; CHECK:  0x[[T2]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[T3:[0-9]+]] "int *")
+
+; CHECK:DW_TAG_LLVM_annotation
+; CHECK-NEXT: DW_AT_name("btf_type_tag")
+; CHECK-NEXT: DW_AT_const_value ("tag1")
+
+; CHECK:NULL
+
+; CHECK:  0x[[T3]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[#]] "int")
+
+!13 = !{i32 7, !"Dwarf Version", i32 4}
+!14 = !{i32 2, !"Debug Info Version", i32 3}
+!15 = !{i32 1, !"wchar_size", i32 4}
+!16 = !{i32 7, !"uwtable", i32 1}
+!17 = !{i32 7, !"frame-pointer", i32 2}
+!18 = !{!"clang version 14.0.0 (https://github.com/llvm/llvm-project.git 2c240a5eefae1a945dfd36cdaa0c677eca90dd82)"}
Index: llvm/test/Bitcode/attr-btf_type_tag.ll
===
--- /dev/null
+++ llvm/test/Bitcode/attr-btf_type_tag.ll
@@ -0,0 +1,36 @@
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
+;
+; Source:
+;   #define __tag1 __attribute__((btf_type_tag("tag1")))
+;   int __tag1 *g;
+; Compilation flag:
+;   clang -S -g -emit-llvm test.c
+
+@g = dso_local global i32* null, align 8, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!9, !10, !11, !12, !13}
+!llvm.ident = !{!14}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 2, type: !5, 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 248122328bfefe82608a2e110af3a3ff04279ddf)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm/btf_tag_type")
+!4 = !{!0}
+!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64, annotations: !7)
+!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!7 = !{!8}
+!8 = !{!"btf_type_tag", !"tag1"}
+
+; CHECK:   distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, 

[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-10-25 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song updated this revision to Diff 382088.
yonghong-song added a comment.

- removed AttributedBTFType subclass. Instead of using corresponding *TypeLoc 
to retrieve string argument for btf_type_tag attribute.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/AST/TypePrinter.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/attr-btf_type_tag-func.c
  clang/test/CodeGen/attr-btf_type_tag-typedef-field.c
  clang/test/CodeGen/attr-btf_type_tag-var.c
  clang/test/Sema/attr-btf_type_tag.c
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/IR/DIBuilder.cpp
  llvm/test/Bitcode/attr-btf_type_tag.ll
  llvm/test/DebugInfo/attr-btf_type_tag.ll

Index: llvm/test/DebugInfo/attr-btf_type_tag.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/attr-btf_type_tag.ll
@@ -0,0 +1,62 @@
+; REQUIRES: x86-registered-target
+; RUN: llc -filetype=obj -o %t %s
+; RUN: llvm-dwarfdump -debug-info %t | FileCheck %s
+; Source:
+;   #define __tag1 __attribute__((btf_type_tag("tag1")))
+;   #define __tag2 __attribute__((btf_type_tag("tag2")))
+;
+;   int * __tag1 * __tag2 *g;
+; Compilation flag:
+;   clang -target x86_64 -g -S -emit-llvm t.c
+
+@g = dso_local global i32*** null, align 8, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!13, !14, !15, !16, !17}
+!llvm.ident = !{!18}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 4, type: !5, 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 2c240a5eefae1a945dfd36cdaa0c677eca90dd82)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "t.c", directory: "/home/yhs/work/tests/llvm/btf_tag_type")
+!4 = !{!0}
+!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64, annotations: !11)
+!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64, annotations: !9)
+!7 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)
+!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!9 = !{!10}
+!10 = !{!"btf_type_tag", !"tag1"}
+!11 = !{!12}
+!12 = !{!"btf_type_tag", !"tag2"}
+
+; CHECK:  DW_TAG_variable
+; CHECK-NEXT:   DW_AT_name  ("g")
+; CHECK-NEXT:   DW_AT_type  (0x[[T1:[0-9]+]] "int ***")
+
+; CHECK:  0x[[T1]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[T2:[0-9]+]] "int **")
+
+; CHECK:DW_TAG_LLVM_annotation
+; CHECK-NEXT: DW_AT_name("btf_type_tag")
+; CHECK-NEXT: DW_AT_const_value ("tag2")
+
+; CHECK:NULL
+
+; CHECK:  0x[[T2]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[T3:[0-9]+]] "int *")
+
+; CHECK:DW_TAG_LLVM_annotation
+; CHECK-NEXT: DW_AT_name("btf_type_tag")
+; CHECK-NEXT: DW_AT_const_value ("tag1")
+
+; CHECK:NULL
+
+; CHECK:  0x[[T3]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[#]] "int")
+
+!13 = !{i32 7, !"Dwarf Version", i32 4}
+!14 = !{i32 2, !"Debug Info Version", i32 3}
+!15 = !{i32 1, !"wchar_size", i32 4}
+!16 = !{i32 7, !"uwtable", i32 1}
+!17 = !{i32 7, !"frame-pointer", i32 2}
+!18 = !{!"clang version 14.0.0 (https://github.com/llvm/llvm-project.git 2c240a5eefae1a945dfd36cdaa0c677eca90dd82)"}
Index: llvm/test/Bitcode/attr-btf_type_tag.ll
===
--- /dev/null
+++ llvm/test/Bitcode/attr-btf_type_tag.ll
@@ -0,0 +1,36 @@
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
+;
+; Source:
+;   #define __tag1 __attribute__((btf_type_tag("tag1")))
+;   int __tag1 *g;
+; Compilation flag:
+;   clang -S -g -emit-llvm test.c
+
+@g = dso_local global i32* null, align 8, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!9, !10, !11, !12, !13}
+!llvm.ident = !{!14}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 2, type: !5, 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 248122328bfefe82608a2e110af3a3ff04279ddf)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm/btf_tag_type")
+!4 = !{!0}
+!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64, annotations: !7)
+!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!7 = !{!8}
+!8 = 

[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-10-21 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

In D99#3078184 , @aaron.ballman 
wrote:

> I reviewed this a bit, but I think it might be heading in a slightly wrong 
> direction. I think you should be using an `AttributedType` but I don't think 
> we need to add `AttributedBTFType` as a subclass to do this. An 
> `AttributedType` holds the type kind information in it, but you should be 
> able to access an `AttributedTypeLoc` object to get to the semantic attribute 
> to access the string argument to the attribute. Generally, you'd call 
> `getTypeSourceInfo()` on the declaration to get the type source info for its 
> type, you can call `getTypeLoc()` on that object to get a generic `TypeLoc` 
> object, and then call `getAs()` on that to turn it into an 
> `AttributedTypeLoc` and from there you can call `getAttr()` to get the `Attr 
> *` for the semantic attribute.

Thanks for detailed explanation. This is very useful. I will look into this. I 
agree with your approach and I myself also have concern with 
`AttributedBTFType`. I will just use `AttributedType` going forward.




Comment at: clang/include/clang/AST/PropertiesBase.td:134
   def ExprRef : SubclassPropertyType<"Expr", StmtRef>;
+def String : PropertyType<"std::string">;
 def TemplateArgument : PropertyType;

aaron.ballman wrote:
> Is `std::string` really the correct type to be using for AST serialization? 
> Can we use `StringRef` here as well?
I think StringRef may be possible. I will investigate.



Comment at: clang/include/clang/AST/TypeLoc.h:896
+: public InheritingConcreteTypeLoc {};
+

aaron.ballman wrote:
> Is this actually needed? I would have assumed the `AttributedTypeLoc` would 
> suffice.
Honestly I am not 100%. But since we will AttributedType and this should not be 
an issue any more.



Comment at: clang/include/clang/Basic/Attr.td:1850
+  let Args = [StringArgument<"BTFTypeTag">];
+  let Documentation = [Undocumented];
+  let LangOpts = [COnly];

aaron.ballman wrote:
> No new, undocumented attributes please.
Will do in the next revision.



Comment at: clang/include/clang/Serialization/ASTRecordWriter.h:286-287
 
+  void writeString(StringRef Str) { return AddString(Str); }
+
   /// Emit a path.

aaron.ballman wrote:
> This appears to be unused, can be removed?
Not 100% sure whether this will be used during serialization/deserialization. I 
will double check.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1152
+  StringRef BTFTypeTag = AT->getBTFTypeTag();
+  if (BTFTypeTag[0]) {
+llvm::Metadata *Ops[2] = {

aaron.ballman wrote:
> Should this be checking `!BTFTypeTag.empty()` instead?
Yes, that is true. This probably from old previous revision leftover which I am 
using a char array and the first '\0' indicating no attribute.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-10-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I reviewed this a bit, but I think it might be heading in a slightly wrong 
direction. I think you should be using an `AttributedType` but I don't think we 
need to add `AttributedBTFType` as a subclass to do this. An `AttributedType` 
holds the type kind information in it, but you should be able to access an 
`AttributedTypeLoc` object to get to the semantic attribute to access the 
string argument to the attribute. Generally, you'd call `getTypeSourceInfo()` 
on the declaration to get the type source info for its type, you can call 
`getTypeLoc()` on that object to get a generic `TypeLoc` object, and then call 
`getAs()` on that to turn it into an `AttributedTypeLoc` and 
from there you can call `getAttr()` to get the `Attr *` for the semantic 
attribute.




Comment at: clang/include/clang/AST/ASTContext.h:1562-1563
 
+  QualType getAttributedBTFType(attr::Kind attrKind, QualType modifiedType,
+QualType equivalentType, StringRef BTFTypeTag);
+





Comment at: clang/include/clang/AST/PropertiesBase.td:134
   def ExprRef : SubclassPropertyType<"Expr", StmtRef>;
+def String : PropertyType<"std::string">;
 def TemplateArgument : PropertyType;

Is `std::string` really the correct type to be using for AST serialization? Can 
we use `StringRef` here as well?



Comment at: clang/include/clang/AST/Type.h:4779-4783
+  AttributedBTFType(QualType canon, attr::Kind attrKind, QualType modified,
+QualType equivalent, StringRef BTFTypeTag)
+  : AttributedType(AttributedBTF, canon, attrKind, modified, equivalent) {
+this->BTFTypeTag = BTFTypeTag;
+  }





Comment at: clang/include/clang/AST/TypeLoc.h:896
+: public InheritingConcreteTypeLoc {};
+

Is this actually needed? I would have assumed the `AttributedTypeLoc` would 
suffice.



Comment at: clang/include/clang/Basic/Attr.td:1850
+  let Args = [StringArgument<"BTFTypeTag">];
+  let Documentation = [Undocumented];
+  let LangOpts = [COnly];

No new, undocumented attributes please.



Comment at: clang/include/clang/Serialization/ASTRecordWriter.h:286-287
 
+  void writeString(StringRef Str) { return AddString(Str); }
+
   /// Emit a path.

This appears to be unused, can be removed?



Comment at: clang/lib/AST/ASTContext.cpp:4636-4656
+QualType ASTContext::getAttributedBTFType(attr::Kind attrKind,
+  QualType modifiedType,
+  QualType equivalentType,
+  StringRef BTFTypeTag) {
+  llvm::FoldingSetNodeID id;
+  AttributedBTFType::Profile(id, attrKind, modifiedType, equivalentType,
+ BTFTypeTag);





Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1152
+  StringRef BTFTypeTag = AT->getBTFTypeTag();
+  if (BTFTypeTag[0]) {
+llvm::Metadata *Ops[2] = {

Should this be checking `!BTFTypeTag.empty()` instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-10-20 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

@aaron.ballman ping. Did you get time to look at this patch? Esp. any comments 
on this approach with a subclass AttributedBTF vs. putting a StringRef directly 
in Attributed?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-10-15 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song updated this revision to Diff 380049.
yonghong-song added a subscriber: urnathan.
yonghong-song added a comment.

- fix a few clang-format issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeLoc.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/TypeNodes.td
  clang/include/clang/Serialization/ASTRecordWriter.h
  clang/include/clang/Serialization/TypeBitCodes.def
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/CodeGen/attr-btf_type_tag-conv-var.c
  clang/test/CodeGen/attr-btf_type_tag-typedef-field.c
  clang/test/Sema/attr-btf_type_tag.c
  clang/tools/libclang/CIndex.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/test/DebugInfo/attr-btf_type_tag.ll

Index: llvm/test/DebugInfo/attr-btf_type_tag.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/attr-btf_type_tag.ll
@@ -0,0 +1,62 @@
+; REQUIRES: x86-registered-target
+; RUN: llc -filetype=obj -o %t %s
+; RUN: llvm-dwarfdump -debug-info %t | FileCheck %s
+; Source:
+;   #define __tag1 __attribute__((btf_type_tag("tag1")))
+;   #define __tag2 __attribute__((btf_type_tag("tag2")))
+;
+;   int * __tag1 * __tag2 *g;
+; Compilation flag:
+;   clang -target x86_64 -g -S -emit-llvm t.c
+
+@g = dso_local global i32*** null, align 8, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!13, !14, !15, !16, !17}
+!llvm.ident = !{!18}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 4, type: !5, 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 2c240a5eefae1a945dfd36cdaa0c677eca90dd82)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "t.c", directory: "/home/yhs/work/tests/llvm/btf_tag_type")
+!4 = !{!0}
+!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64, annotations: !11)
+!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64, annotations: !9)
+!7 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)
+!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!9 = !{!10}
+!10 = !{!"btf_type_tag", !"tag1"}
+!11 = !{!12}
+!12 = !{!"btf_type_tag", !"tag2"}
+
+; CHECK:  DW_TAG_variable
+; CHECK-NEXT:   DW_AT_name  ("g")
+; CHECK-NEXT:   DW_AT_type  (0x[[T1:[0-9]+]] "int ***")
+
+; CHECK:  0x[[T1]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[T2:[0-9]+]] "int **")
+
+; CHECK:DW_TAG_LLVM_annotation
+; CHECK-NEXT: DW_AT_name("btf_type_tag")
+; CHECK-NEXT: DW_AT_const_value ("tag2")
+
+; CHECK:NULL
+
+; CHECK:  0x[[T2]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[T3:[0-9]+]] "int *")
+
+; CHECK:DW_TAG_LLVM_annotation
+; CHECK-NEXT: DW_AT_name("btf_type_tag")
+; CHECK-NEXT: DW_AT_const_value ("tag1")
+
+; CHECK:NULL
+
+; CHECK:  0x[[T3]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[#]] "int")
+
+!13 = !{i32 7, !"Dwarf Version", i32 4}
+!14 = !{i32 2, !"Debug Info Version", i32 3}
+!15 = !{i32 1, !"wchar_size", i32 4}
+!16 = !{i32 7, !"uwtable", i32 1}
+!17 = !{i32 7, !"frame-pointer", i32 2}
+!18 = !{!"clang version 14.0.0 (https://github.com/llvm/llvm-project.git 2c240a5eefae1a945dfd36cdaa0c677eca90dd82)"}
Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -287,17 +287,16 @@
 0, 0, None, DINode::FlagZero);
 }
 
-DIDerivedType *DIBuilder::createPointerType(
-DIType *PointeeTy,
-uint64_t SizeInBits,
-uint32_t AlignInBits,
-Optional DWARFAddressSpace,
-StringRef Name) {
+DIDerivedType *
+DIBuilder::createPointerType(DIType *PointeeTy, uint64_t SizeInBits,
+ uint32_t AlignInBits,
+ Optional DWARFAddressSpace,
+ StringRef Name, DINodeArray Annotations) {
   // FIXME: Why is there 

[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-10-14 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song updated this revision to Diff 379807.
yonghong-song added a comment.

- fix clang-format issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeLoc.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/TypeNodes.td
  clang/include/clang/Serialization/ASTRecordWriter.h
  clang/include/clang/Serialization/TypeBitCodes.def
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/CodeGen/attr-btf_type_tag-conv-var.c
  clang/test/CodeGen/attr-btf_type_tag-typedef-field.c
  clang/test/Sema/attr-btf_type_tag.c
  clang/tools/libclang/CIndex.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/test/DebugInfo/attr-btf_type_tag.ll

Index: llvm/test/DebugInfo/attr-btf_type_tag.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/attr-btf_type_tag.ll
@@ -0,0 +1,62 @@
+; REQUIRES: x86-registered-target
+; RUN: llc -filetype=obj -o %t %s
+; RUN: llvm-dwarfdump -debug-info %t | FileCheck %s
+; Source:
+;   #define __tag1 __attribute__((btf_type_tag("tag1")))
+;   #define __tag2 __attribute__((btf_type_tag("tag2")))
+;
+;   int * __tag1 * __tag2 *g;
+; Compilation flag:
+;   clang -target x86_64 -g -S -emit-llvm t.c
+
+@g = dso_local global i32*** null, align 8, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!13, !14, !15, !16, !17}
+!llvm.ident = !{!18}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 4, type: !5, 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 2c240a5eefae1a945dfd36cdaa0c677eca90dd82)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "t.c", directory: "/home/yhs/work/tests/llvm/btf_tag_type")
+!4 = !{!0}
+!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64, annotations: !11)
+!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64, annotations: !9)
+!7 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)
+!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!9 = !{!10}
+!10 = !{!"btf_type_tag", !"tag1"}
+!11 = !{!12}
+!12 = !{!"btf_type_tag", !"tag2"}
+
+; CHECK:  DW_TAG_variable
+; CHECK-NEXT:   DW_AT_name  ("g")
+; CHECK-NEXT:   DW_AT_type  (0x[[T1:[0-9]+]] "int ***")
+
+; CHECK:  0x[[T1]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[T2:[0-9]+]] "int **")
+
+; CHECK:DW_TAG_LLVM_annotation
+; CHECK-NEXT: DW_AT_name("btf_type_tag")
+; CHECK-NEXT: DW_AT_const_value ("tag2")
+
+; CHECK:NULL
+
+; CHECK:  0x[[T2]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[T3:[0-9]+]] "int *")
+
+; CHECK:DW_TAG_LLVM_annotation
+; CHECK-NEXT: DW_AT_name("btf_type_tag")
+; CHECK-NEXT: DW_AT_const_value ("tag1")
+
+; CHECK:NULL
+
+; CHECK:  0x[[T3]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[#]] "int")
+
+!13 = !{i32 7, !"Dwarf Version", i32 4}
+!14 = !{i32 2, !"Debug Info Version", i32 3}
+!15 = !{i32 1, !"wchar_size", i32 4}
+!16 = !{i32 7, !"uwtable", i32 1}
+!17 = !{i32 7, !"frame-pointer", i32 2}
+!18 = !{!"clang version 14.0.0 (https://github.com/llvm/llvm-project.git 2c240a5eefae1a945dfd36cdaa0c677eca90dd82)"}
Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -292,12 +292,13 @@
 uint64_t SizeInBits,
 uint32_t AlignInBits,
 Optional DWARFAddressSpace,
-StringRef Name) {
+StringRef Name,
+DINodeArray Annotations) {
   // FIXME: Why is there a name here?
   return DIDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name,
 nullptr, 0, nullptr, PointeeTy, SizeInBits,
 AlignInBits, 0, DWARFAddressSpace,
-DINode::FlagZero);
+DINode::FlagZero, nullptr, Annotations);
 }
 
 DIDerivedType 

[PATCH] D111199: [Clang][LLVM][Attr] support btf_type_tag attribute

2021-10-14 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song updated this revision to Diff 379772.
yonghong-song retitled this revision from "[POC][BTF] support btf_type_tag 
attribute" to "[Clang][LLVM][Attr] support btf_type_tag attribute".
yonghong-song edited the summary of this revision.
yonghong-song added a comment.
Herald added subscribers: arphaman, martong.

- remove POC tag and now the implementation is complete
- in this patch, AttributedBTFType is created as a subclass of AttributedType. 
This makes quite some changes in the codebase for processing or handling 
AttributedBTFType. Alternatively, we could amend existing AttributedType to 
have a StringRef to store btf_tag. We can discuss which way is better.
- I may have missed some testing. Let me know what I have missed and I can add 
them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeLoc.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/TypeNodes.td
  clang/include/clang/Serialization/ASTRecordWriter.h
  clang/include/clang/Serialization/TypeBitCodes.def
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/CodeGen/attr-btf_type_tag-conv-var.c
  clang/test/CodeGen/attr-btf_type_tag-typedef-field.c
  clang/test/Sema/attr-btf_type_tag.c
  clang/tools/libclang/CIndex.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/test/DebugInfo/attr-btf_type_tag.ll

Index: llvm/test/DebugInfo/attr-btf_type_tag.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/attr-btf_type_tag.ll
@@ -0,0 +1,62 @@
+; REQUIRES: x86-registered-target
+; RUN: llc -filetype=obj -o %t %s
+; RUN: llvm-dwarfdump -debug-info %t | FileCheck %s
+; Source:
+;   #define __tag1 __attribute__((btf_type_tag("tag1")))
+;   #define __tag2 __attribute__((btf_type_tag("tag2")))
+;
+;   int * __tag1 * __tag2 *g;
+; Compilation flag:
+;   clang -target x86_64 -g -S -emit-llvm t.c
+
+@g = dso_local global i32*** null, align 8, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!13, !14, !15, !16, !17}
+!llvm.ident = !{!18}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 4, type: !5, 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 2c240a5eefae1a945dfd36cdaa0c677eca90dd82)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "t.c", directory: "/home/yhs/work/tests/llvm/btf_tag_type")
+!4 = !{!0}
+!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64, annotations: !11)
+!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64, annotations: !9)
+!7 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)
+!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!9 = !{!10}
+!10 = !{!"btf_type_tag", !"tag1"}
+!11 = !{!12}
+!12 = !{!"btf_type_tag", !"tag2"}
+
+; CHECK:  DW_TAG_variable
+; CHECK-NEXT:   DW_AT_name  ("g")
+; CHECK-NEXT:   DW_AT_type  (0x[[T1:[0-9]+]] "int ***")
+
+; CHECK:  0x[[T1]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[T2:[0-9]+]] "int **")
+
+; CHECK:DW_TAG_LLVM_annotation
+; CHECK-NEXT: DW_AT_name("btf_type_tag")
+; CHECK-NEXT: DW_AT_const_value ("tag2")
+
+; CHECK:NULL
+
+; CHECK:  0x[[T2]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[T3:[0-9]+]] "int *")
+
+; CHECK:DW_TAG_LLVM_annotation
+; CHECK-NEXT: DW_AT_name("btf_type_tag")
+; CHECK-NEXT: DW_AT_const_value ("tag1")
+
+; CHECK:NULL
+
+; CHECK:  0x[[T3]]: DW_TAG_pointer_type
+; CHECK-NEXT:   DW_AT_type  (0x[[#]] "int")
+
+!13 = !{i32 7, !"Dwarf Version", i32 4}
+!14 = !{i32 2, !"Debug Info Version", i32 3}
+!15 = !{i32 1, !"wchar_size", i32 4}
+!16 = !{i32 7, !"uwtable", i32 1}
+!17 = !{i32 7, !"frame-pointer", i32 2}
+!18 = !{!"clang version 14.0.0 (https://github.com/llvm/llvm-project.git 2c240a5eefae1a945dfd36cdaa0c677eca90dd82)"}
Index: llvm/lib/IR/DIBuilder.cpp
===
---