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

- change to use DeclOrTypeAttr in Attr.td to indicate the attribute can be used 
for declarations or type qualifier.
- add explanation of why the change in AttrDocs.td and the test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110116

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_tag.c


Index: clang/test/Sema/attr-btf_tag.c
===================================================================
--- clang/test/Sema/attr-btf_tag.c
+++ clang/test/Sema/attr-btf_tag.c
@@ -40,3 +40,11 @@
 int __tag1 foo(struct t1 *arg __tag1, struct t2 *arg2) {
   return arg->a + arg2->a;
 }
+
+void * convert(long arg) {
+  /* FIXME: the attribute __tag1 is accepted but didn't really do type 
conversion
+   * or enforce type checking. This is to permit linux kernel build with 
btf_tag
+   * attribute.
+   */
+  return (void __tag1 *)arg;
+}
Index: clang/lib/Sema/SemaType.cpp
===================================================================
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -8127,6 +8127,12 @@
     case ParsedAttr::IgnoredAttribute:
       break;
 
+    case ParsedAttr::AT_BTFTag:
+      // FIXME: Linux kernel may also use this attribute for type casting 
check,
+      // which clang doesn's support for now. Let us ignore them so linux 
kernel
+      // build won't break.
+      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
@@ -1702,6 +1702,7 @@
   case attr::UPtr:
   case attr::AddressSpace:
   case attr::CmseNSCall:
+  case attr::BTFTag:
     llvm_unreachable("This attribute should have been handled already");
 
   case attr::NSReturnsRetained:
Index: clang/include/clang/Basic/AttrDocs.td
===================================================================
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -2019,6 +2019,9 @@
 function, function parameter or variable declaration. If -g is specified,
 the ``ARGUMENT`` info will be preserved in IR and be emitted to dwarf.
 For BPF targets, the ``ARGUMENT`` info will be emitted to .BTF ELF section too.
+
+The attribute can also be used as a type qualifier. Right now it is accepted
+and silently ignored in order to permit linux kernel build with the attribute.
   }];
 }
 
Index: clang/include/clang/Basic/Attr.td
===================================================================
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1835,7 +1835,7 @@
   let LangOpts = [COnly];
 }
 
-def BTFTag : InheritableAttr {
+def BTFTag : DeclOrTypeAttr {
   let Spellings = [Clang<"btf_tag">];
   let Args = [StringArgument<"BTFTag">];
   let Subjects = SubjectList<[Var, Function, Record, Field], ErrorDiag>;


Index: clang/test/Sema/attr-btf_tag.c
===================================================================
--- clang/test/Sema/attr-btf_tag.c
+++ clang/test/Sema/attr-btf_tag.c
@@ -40,3 +40,11 @@
 int __tag1 foo(struct t1 *arg __tag1, struct t2 *arg2) {
   return arg->a + arg2->a;
 }
+
+void * convert(long arg) {
+  /* FIXME: the attribute __tag1 is accepted but didn't really do type conversion
+   * or enforce type checking. This is to permit linux kernel build with btf_tag
+   * attribute.
+   */
+  return (void __tag1 *)arg;
+}
Index: clang/lib/Sema/SemaType.cpp
===================================================================
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -8127,6 +8127,12 @@
     case ParsedAttr::IgnoredAttribute:
       break;
 
+    case ParsedAttr::AT_BTFTag:
+      // FIXME: Linux kernel may also use this attribute for type casting check,
+      // which clang doesn's support for now. Let us ignore them so linux kernel
+      // build won't break.
+      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
@@ -1702,6 +1702,7 @@
   case attr::UPtr:
   case attr::AddressSpace:
   case attr::CmseNSCall:
+  case attr::BTFTag:
     llvm_unreachable("This attribute should have been handled already");
 
   case attr::NSReturnsRetained:
Index: clang/include/clang/Basic/AttrDocs.td
===================================================================
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -2019,6 +2019,9 @@
 function, function parameter or variable declaration. If -g is specified,
 the ``ARGUMENT`` info will be preserved in IR and be emitted to dwarf.
 For BPF targets, the ``ARGUMENT`` info will be emitted to .BTF ELF section too.
+
+The attribute can also be used as a type qualifier. Right now it is accepted
+and silently ignored in order to permit linux kernel build with the attribute.
   }];
 }
 
Index: clang/include/clang/Basic/Attr.td
===================================================================
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1835,7 +1835,7 @@
   let LangOpts = [COnly];
 }
 
-def BTFTag : InheritableAttr {
+def BTFTag : DeclOrTypeAttr {
   let Spellings = [Clang<"btf_tag">];
   let Args = [StringArgument<"BTFTag">];
   let Subjects = SubjectList<[Var, Function, Record, Field], ErrorDiag>;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to