[clang] 334e07f - [RISCV] Disallow target attribute use in multiversioning (#85899)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 11 19:59:10 PDT 2024
Author: Piyou Chen
Date: 2024-04-12T10:59:06+08:00
New Revision: 334e07f18e6f2fbc84579f7cac3cdd29d0d7cce0
URL: https://github.com/llvm/llvm-project/commit/334e07f18e6f2fbc84579f7cac3cdd29d0d7cce0
DIFF: https://github.com/llvm/llvm-project/commit/334e07f18e6f2fbc84579f7cac3cdd29d0d7cce0.diff
LOG: [RISCV] Disallow target attribute use in multiversioning (#85899)
For RISC-V target only `target_clones` and `target_version` can enable
function multiversion(FMV).
This patch make target attribute trigger redefinition instead of emit
FMV.
Here is spec
https://github.com/riscv-non-isa/riscv-c-api-doc/blob/master/riscv-c-api.md#__attribute__targetattr-string
Added:
clang/test/Sema/attr-target-riscv.c
Modified:
clang/lib/Sema/SemaDecl.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index a4699d6ba2c735..691e170cd05144 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11911,8 +11911,14 @@ static bool CheckMultiVersionFunction(Sema &S, FunctionDecl *NewFD,
return false;
}
+ const llvm::Triple &T = S.getASTContext().getTargetInfo().getTriple();
+
// Target attribute on AArch64 is not used for multiversioning
- if (NewTA && S.getASTContext().getTargetInfo().getTriple().isAArch64())
+ if (NewTA && T.isAArch64())
+ return false;
+
+ // Target attribute on RISCV is not used for multiversioning
+ if (NewTA && T.isRISCV())
return false;
if (!OldDecl || !OldDecl->getAsFunction() ||
diff --git a/clang/test/Sema/attr-target-riscv.c b/clang/test/Sema/attr-target-riscv.c
new file mode 100644
index 00000000000000..ed4e2915d6c6ef
--- /dev/null
+++ b/clang/test/Sema/attr-target-riscv.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple riscv64-linux-gnu -target-feature +i -fsyntax-only -verify -std=c2x %s
+
+//expected-note at +1 {{previous definition is here}}
+int __attribute__((target("arch=rv64g"))) foo(void) { return 0; }
+//expected-error at +1 {{redefinition of 'foo'}}
+int __attribute__((target("arch=rv64gc"))) foo(void) { return 0; }
More information about the cfe-commits
mailing list