https://github.com/BeMg updated https://github.com/llvm/llvm-project/pull/85899
>From 894c0975638a99c84fde8d1ea5c845e5cdbf32f4 Mon Sep 17 00:00:00 2001 From: Piyou Chen <piyou.c...@sifive.com> Date: Mon, 18 Mar 2024 05:07:14 -0700 Subject: [PATCH 1/3] [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 5a23179dfbbf44..0aa0350d5c562f 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -11916,6 +11916,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 e6b7a2da5cb6dccd85aa3b7a12bffcc2b4a31270 Mon Sep 17 00:00:00 2001 From: Piyou Chen <piyou.c...@sifive.com> Date: Mon, 1 Apr 2024 23:21:25 -0700 Subject: [PATCH 2/3] 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@+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; } >From b9a2a5e3dda4088056da64cf80504a542ff3ddcd Mon Sep 17 00:00:00 2001 From: Piyou Chen <piyou.c...@sifive.com> Date: Sun, 7 Apr 2024 22:14:46 -0700 Subject: [PATCH 3/3] Share Triple for AArch64 and RISCV --- clang/lib/Sema/SemaDecl.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 0aa0350d5c562f..92d2b2f6120bc9 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -11912,12 +11912,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 && S.getASTContext().getTargetInfo().getTriple().isRISCV()) + if (NewTA && T.isRISCV()) return false; if (!OldDecl || !OldDecl->getAsFunction() || _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits