diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -1838,7 +1838,8 @@ def BTFTag : DeclOrTypeAttr { let Spellings = [Clang<"btf_tag">]; let Args = [StringArgument<"BTFTag">]; - let Subjects = SubjectList<[Var, Function, Record, Field], ErrorDiag>; + let Subjects = SubjectList<[Var, Function, Record, Field, TypedefName], + ErrorDiag>; let Documentation = [BTFTagDocs]; let LangOpts = [COnly]; } diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -2016,9 +2016,10 @@ let Content = [{ Clang supports the ``__attribute__((btf_tag("ARGUMENT")))`` attribute for all 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. +function, function parameter, variable or typedef 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 diff --git a/clang/test/Misc/pragma-attribute-supported-attributes-list.test b/clang/test/Misc/pragma-attribute-supported-attributes-list.test --- a/clang/test/Misc/pragma-attribute-supported-attributes-list.test +++ b/clang/test/Misc/pragma-attribute-supported-attributes-list.test @@ -22,7 +22,7 @@ // CHECK-NEXT: Assumption (SubjectMatchRule_function, SubjectMatchRule_objc_method) // CHECK-NEXT: Availability ((SubjectMatchRule_record, SubjectMatchRule_enum, SubjectMatchRule_enum_constant, SubjectMatchRule_field, SubjectMatchRule_function, SubjectMatchRule_namespace, SubjectMatchRule_objc_category, SubjectMatchRule_objc_implementation, SubjectMatchRule_objc_interface, SubjectMatchRule_objc_method, SubjectMatchRule_objc_property, SubjectMatchRule_objc_protocol, SubjectMatchRule_record, SubjectMatchRule_type_alias, SubjectMatchRule_variable)) // CHECK-NEXT: BPFPreserveAccessIndex (SubjectMatchRule_record) -// CHECK-NEXT: BTFTag (SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_record, SubjectMatchRule_field) +// CHECK-NEXT: BTFTag (SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_record, SubjectMatchRule_field, SubjectMatchRule_type_alias) // CHECK-NEXT: BuiltinAlias (SubjectMatchRule_function) // CHECK-NEXT: CFAuditedTransfer (SubjectMatchRule_function) // CHECK-NEXT: CFConsumed (SubjectMatchRule_variable_is_parameter) diff --git a/clang/test/Sema/attr-btf_tag.c b/clang/test/Sema/attr-btf_tag.c --- a/clang/test/Sema/attr-btf_tag.c +++ b/clang/test/Sema/attr-btf_tag.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -x c -triple x86_64-pc-linux-gnu -dwarf-version=4 -fsyntax-only -verify %s +// RUN: %clang_cc1 -x c -std=c2x -triple x86_64-pc-linux-gnu -dwarf-version=4 -fsyntax-only -verify %s #define __tag1 __attribute__((btf_tag("tag1"))) #define __tag2 __attribute__((btf_tag("tag2"))) @@ -25,15 +25,15 @@ enum e1 { E1 -} __tag1; // expected-error {{'btf_tag' attribute only applies to variables, functions, structs, unions, classes, and non-static data members}} +} __tag1; // expected-error {{'btf_tag' attribute only applies to variables, functions, structs, unions, classes, non-static data members, and typedefs}} enum e2 { E2 -} __tag_no_arg; // expected-error {{'btf_tag' attribute only applies to variables, functions, structs, unions, classes, and non-static data members}} +} __tag_no_arg; // expected-error {{'btf_tag' attribute only applies to variables, functions, structs, unions, classes, non-static data members, and typedefs}} enum e3 { E3 -} __tag_2_arg; // expected-error {{'btf_tag' attribute only applies to variables, functions, structs, unions, classes, and non-static data members}} +} __tag_2_arg; // expected-error {{'btf_tag' attribute only applies to variables, functions, structs, unions, classes, non-static data members, and typedefs}} int __tag1 __tag2 foo(struct t1 *arg, struct t2 *arg2); int __tag2 __tag3 foo(struct t1 *arg, struct t2 *arg2); @@ -48,3 +48,13 @@ */ return (void __tag1 *)arg; } + +typedef unsigned * __u1 [[clang::btf_tag("tag1")]]; /* attribute applied to __u1 */ +__u1 convert2(long arg) { + return (__u1)arg; +} + +typedef struct { int a; int b; } __u2 [[clang::btf_tag("tag1")]]; /* attribute applied to __u2 */ +__u2 * convert3(long arg) { + return (__u2 *)arg; +}