Skip to content

Commit 334e07f

Browse files
authored
[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
1 parent 3a28177 commit 334e07f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11911,8 +11911,14 @@ static bool CheckMultiVersionFunction(Sema &S, FunctionDecl *NewFD,
1191111911
return false;
1191211912
}
1191311913

11914+
const llvm::Triple &T = S.getASTContext().getTargetInfo().getTriple();
11915+
1191411916
// Target attribute on AArch64 is not used for multiversioning
11915-
if (NewTA && S.getASTContext().getTargetInfo().getTriple().isAArch64())
11917+
if (NewTA && T.isAArch64())
11918+
return false;
11919+
11920+
// Target attribute on RISCV is not used for multiversioning
11921+
if (NewTA && T.isRISCV())
1191611922
return false;
1191711923

1191811924
if (!OldDecl || !OldDecl->getAsFunction() ||

clang/test/Sema/attr-target-riscv.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %clang_cc1 -triple riscv64-linux-gnu -target-feature +i -fsyntax-only -verify -std=c2x %s
2+
3+
//expected-note@+1 {{previous definition is here}}
4+
int __attribute__((target("arch=rv64g"))) foo(void) { return 0; }
5+
//expected-error@+1 {{redefinition of 'foo'}}
6+
int __attribute__((target("arch=rv64gc"))) foo(void) { return 0; }

0 commit comments

Comments
 (0)