Skip to content

Commit

Permalink
[RISCV] Disallow target attribute use in multiversioning (#85899)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
BeMg committed Apr 12, 2024
1 parent 3a28177 commit 334e07f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ||
Expand Down
6 changes: 6 additions & 0 deletions clang/test/Sema/attr-target-riscv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: %clang_cc1 -triple riscv64-linux-gnu -target-feature +i -fsyntax-only -verify -std=c2x %s

//expected-note@+1 {{previous definition is here}}
int __attribute__((target("arch=rv64g"))) foo(void) { return 0; }
//expected-error@+1 {{redefinition of 'foo'}}
int __attribute__((target("arch=rv64gc"))) foo(void) { return 0; }

0 comments on commit 334e07f

Please sign in to comment.