Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -3282,6 +3282,8 @@ def warn_unsupported_target_attribute
"attribute string; '%select{target|target_clones|target_version}3' "
"attribute ignored">,
InGroup<IgnoredAttributes>;
def err_target_version_unsupported
: Error<"target_version attribute is not supported on this target">;
def err_attribute_unsupported
: Error<"%0 attribute is not supported on targets missing %1;"
" specify an appropriate -march= or -mcpu=">;
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3040,6 +3040,11 @@ bool Sema::checkTargetVersionAttr(SourceLocation LiteralLoc, Decl *D,
enum FirstParam { Unsupported };
enum SecondParam { None };
enum ThirdParam { Target, TargetClones, TargetVersion };

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. Dropped.

if (!Context.getTargetInfo().getTriple().isRISCV() &&
!Context.getTargetInfo().getTriple().isAArch64())
return Diag(LiteralLoc, diag::err_target_version_unsupported);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better way to handle this is to use TargetSpecificAttr for TargetVersion in Attr.td (instead of InheritableAttr). That should automatically handle performing this check and you won't need to add a custom diagnostic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea. This patch now uses the TargetSpecificAttr to enable target_version for AArch64 and RISC-V.


llvm::SmallVector<StringRef, 8> Features;
if (Context.getTargetInfo().getTriple().isRISCV()) {
llvm::SmallVector<StringRef, 8> AttrStrs;
Expand Down
4 changes: 4 additions & 0 deletions clang/test/Sema/attr-target-version-unsupported.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s

//expected-error@+1 {{target_version attribute is not supported on this target}}
int __attribute__((target_version("aes"))) foo(void) { return 3; }
Loading