Skip to content

Commit

Permalink
Revert "[Clang] Ignore BTFTag attr if used as a type attribute"
Browse files Browse the repository at this point in the history
This reverts commit b875343.

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.
  • Loading branch information
yonghong-song committed Oct 11, 2021
1 parent 1131b1e commit c5fb1a0
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 20 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down
4 changes: 0 additions & 4 deletions clang/include/clang/Basic/AttrDocs.td
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}];
}

Expand Down
1 change: 0 additions & 1 deletion clang/lib/AST/TypePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 0 additions & 6 deletions clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 0 additions & 8 deletions clang/test/Sema/attr-btf_tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit c5fb1a0

Please sign in to comment.