[clang] [RISCV] Disallow target attribute use in multiversioning (PR #85899)

Piyou Chen via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 1 23:21:50 PDT 2024


https://github.com/BeMg updated https://github.com/llvm/llvm-project/pull/85899

>From 0bbffb92e7f36957c042cab9a67a483571d9b3f9 Mon Sep 17 00:00:00 2001
From: Piyou Chen <piyou.chen at sifive.com>
Date: Mon, 18 Mar 2024 05:07:14 -0700
Subject: [PATCH 1/2] [RISCV] Disallow target attribute use in multiversioning

---
 clang/lib/Sema/SemaDecl.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 5850cd0ab6b9aa..e543aff77e67ea 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11853,6 +11853,10 @@ static bool CheckMultiVersionFunction(Sema &S, FunctionDecl *NewFD,
   if (NewTA && S.getASTContext().getTargetInfo().getTriple().isAArch64())
     return false;
 
+  // Target attribute on RISCV is not used for multiversioning
+  if (NewTA && S.getASTContext().getTargetInfo().getTriple().isRISCV())
+    return false;
+
   if (!OldDecl || !OldDecl->getAsFunction() ||
       OldDecl->getDeclContext()->getRedeclContext() !=
           NewFD->getDeclContext()->getRedeclContext()) {

>From f0057a2c65a030fc5afa30dee4b08c71cf3451bd Mon Sep 17 00:00:00 2001
From: Piyou Chen <piyou.chen at sifive.com>
Date: Mon, 1 Apr 2024 23:21:25 -0700
Subject: [PATCH 2/2] Add testcase

---
 clang/test/Sema/attr-target-riscv.c | 6 ++++++
 1 file changed, 6 insertions(+)
 create mode 100644 clang/test/Sema/attr-target-riscv.c

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