-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[TargetVersion] Only enable on RISC-V and AArch64 #115991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang Author: Piyou Chen (BeMg) ChangesAddress #115000. This patch constrains the target_version feature to work only on RISC-V and AArch64 to prevent crashes in Clang. Full diff: https://github.com/llvm/llvm-project/pull/115991.diff 2 Files Affected:
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 509d45c0867590..6170c3c10b00ca 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -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 in this target">;
def err_attribute_unsupported
: Error<"%0 attribute is not supported on targets missing %1;"
" specify an appropriate -march= or -mcpu=">;
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index d05d326178e1b8..e2eaa00c666fc2 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3040,6 +3040,11 @@ bool Sema::checkTargetVersionAttr(SourceLocation LiteralLoc, Decl *D,
enum FirstParam { Unsupported };
enum SecondParam { None };
enum ThirdParam { Target, TargetClones, TargetVersion };
+
+ if (!Context.getTargetInfo().getTriple().isRISCV() &&
+ !Context.getTargetInfo().getTriple().isAArch64())
+ return Diag(LiteralLoc, diag::err_target_version_unsupported);
+
llvm::SmallVector<StringRef, 8> Features;
if (Context.getTargetInfo().getTriple().isRISCV()) {
llvm::SmallVector<StringRef, 8> AttrStrs;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use it on X86, so LGTM.
Need a test |
@@ -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 in this target">; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"in this target" -> "on this target"
Update:
|
clang/lib/Sema/SemaDeclAttr.cpp
Outdated
if (!Context.getTargetInfo().getTriple().isRISCV() && | ||
!Context.getTargetInfo().getTriple().isAArch64()) | ||
return Diag(LiteralLoc, diag::err_target_version_unsupported); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
clang/lib/Sema/SemaDeclAttr.cpp
Outdated
@@ -3040,6 +3040,7 @@ bool Sema::checkTargetVersionAttr(SourceLocation LiteralLoc, Decl *D, | |||
enum FirstParam { Unsupported }; | |||
enum SecondParam { None }; | |||
enum ThirdParam { Target, TargetClones, TargetVersion }; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch. Dropped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but can you also add a release note to clang/docs/ReleaseNotes.rst
letting users know about the new restriction and why.
Co-authored-by: Aaron Ballman <[email protected]>
Fix the merge conflict |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/72/builds/5536 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/168/builds/5755 Here is the relevant piece of the build log for the reference
|
…7110)" origin messenge [TargetVersion] Only enable on RISC-V and AArch64 (llvm#115991) Address llvm#115000. This patch constrains the target_version feature to work only on RISC-V and AArch64 to prevent crashes in Clang. --------- Co-authored-by: Aaron Ballman <[email protected]>
…" (#117128) Remain InheritableAttr to avoid the warning `TypePrinter.cpp:1953:10: warning: enumeration value ‘TargetVersion’ not handled in switch` origin messenge [TargetVersion] Only enable on RISC-V and AArch64 (#115991) Address #115000. This patch constrains the target_version feature to work only on RISC-V and AArch64 to prevent crashes in Clang. Co-authored-by: Aaron Ballman <[email protected]>
Address #115000.
This patch constrains the target_version feature to work only on RISC-V and AArch64 to prevent crashes in Clang.