[clang] c5fb1a0 - Revert "[Clang] Ignore BTFTag attr if used as a type attribute"

Yonghong Song via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 11 15:50:16 PDT 2021


Author: Yonghong Song
Date: 2021-10-11T15:34:26-07:00
New Revision: c5fb1a09533ec2ed43a80f39c1592e5ee887ef9e

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

LOG: Revert "[Clang] Ignore BTFTag attr if used as a type attribute"

This reverts commit b875343873a584965daf507d73ff1fe71eab1953.

Per discussion in https://reviews.llvm.org/D111199, instead to make
existing btf_tag attribute as a type-or-decl attribute, we will
make existing btf_tag attribute as a decl only attribute, and
introduce btf_type_tag as a type only attribute. This will make
it easy for cases like typedef where an attribute may be applied
as either a type attribute or a decl attribute.

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index bd6510677fac0..c39657e6c8351 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1836,7 +1836,7 @@ def BPFPreserveAccessIndex : InheritableAttr,
   let LangOpts = [COnly];
 }
 
-def BTFTag : DeclOrTypeAttr {
+def BTFTag : InheritableAttr {
   let Spellings = [Clang<"btf_tag">];
   let Args = [StringArgument<"BTFTag">];
   let Subjects = SubjectList<[Var, Function, Record, Field], ErrorDiag>;

diff  --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td
index d3b0de06e7172..b2b41c3bb4197 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -2019,10 +2019,6 @@ targets. This attribute may be attached to a struct/union, struct/union field,
 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 the linux kernel to build with the
-attribute.
   }];
 }
 

diff  --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 2805916b1f7bb..3c7a6b8b9e953 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -1704,7 +1704,6 @@ void TypePrinter::printAttributedAfter(const AttributedType *T,
   case attr::UPtr:
   case attr::AddressSpace:
   case attr::CmseNSCall:
-  case attr::BTFTag:
     llvm_unreachable("This attribute should have been handled already");
 
   case attr::NSReturnsRetained:

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 11a6d3faf2dd6..d2d54281c63e0 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8127,12 +8127,6 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type,
     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.

diff  --git a/clang/test/Sema/attr-btf_tag.c b/clang/test/Sema/attr-btf_tag.c
index 2ba2515868344..88452fa875b1a 100644
--- a/clang/test/Sema/attr-btf_tag.c
+++ b/clang/test/Sema/attr-btf_tag.c
@@ -40,11 +40,3 @@ int __tag2 __tag3 foo(struct t1 *arg, struct t2 *arg2);
 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;
-}


        


More information about the cfe-commits mailing list