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 @@ -1839,7 +1839,8 @@ def BTFDeclTag : InheritableAttr { let Spellings = [Clang<"btf_decl_tag">]; let Args = [StringArgument<"BTFDeclTag">]; - let Subjects = SubjectList<[Var, Function, Record, Field], ErrorDiag>; + let Subjects = SubjectList<[Var, Function, Record, Field, TypedefName], + ErrorDiag>; let Documentation = [BTFDeclTagDocs]; 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_decl_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. +field, 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. }]; } 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: BTFDeclTag (SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_record, SubjectMatchRule_field) +// CHECK-NEXT: BTFDeclTag (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 @@ -25,18 +25,26 @@ enum e1 { E1 -} __tag1; // expected-error {{'btf_decl_tag' attribute only applies to variables, functions, structs, unions, classes, and non-static data members}} +} __tag1; // expected-error {{'btf_decl_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_decl_tag' attribute only applies to variables, functions, structs, unions, classes, and non-static data members}} +} __tag_no_arg; // expected-error {{'btf_decl_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_decl_tag' attribute only applies to variables, functions, structs, unions, classes, and non-static data members}} +} __tag_2_arg; // expected-error {{'btf_decl_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); int __tag1 foo(struct t1 *arg __tag1, struct t2 *arg2) { return arg->a + arg2->a; } + +typedef unsigned * __u1 __tag1 __tag2; +typedef struct { + int a; +} __t2 __tag1 __tag2; +int convert2(__t2 *arg) { + return arg->a; +}