Author: Pavel Iliin Date: 2023-05-23T17:29:55+01:00 New Revision: b6db864a2fdf2bcfac62b2c0b71b9ed1cc039c27
URL: https://github.com/llvm/llvm-project/commit/b6db864a2fdf2bcfac62b2c0b71b9ed1cc039c27 DIFF: https://github.com/llvm/llvm-project/commit/b6db864a2fdf2bcfac62b2c0b71b9ed1cc039c27.diff LOG: [AArch64][FMV] Prevent target attribute using for multiversioning. On AArch64 for function multiversioning target_version/target_clones attributes should be used. The patch fixes the defect allowing target attribute to cause multiversioning. Differential Revision: https://reviews.llvm.org/D150867 Added: Modified: clang/lib/Sema/SemaDecl.cpp clang/test/Sema/attr-target-version.c Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index adebfe85be45..2f9c8c70e209 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -11540,6 +11540,10 @@ static bool CheckMultiVersionFunction(Sema &S, FunctionDecl *NewFD, return false; } + // Target attribute on AArch64 is not used for multiversioning + if (NewTA && S.getASTContext().getTargetInfo().getTriple().isAArch64()) + return false; + if (!OldDecl || !OldDecl->getAsFunction() || OldDecl->getDeclContext()->getRedeclContext() != NewFD->getDeclContext()->getRedeclContext()) { diff --git a/clang/test/Sema/attr-target-version.c b/clang/test/Sema/attr-target-version.c index c054b037ee84..0cfec5ecb49c 100644 --- a/clang/test/Sema/attr-target-version.c +++ b/clang/test/Sema/attr-target-version.c @@ -15,15 +15,22 @@ int __attribute__((target_version("aes"))) foo(void) { return 1; } //expected-note@+1 {{previous definition is here}} int __attribute__((target_version("default"))) foo(void) { return 2; } -//expected-note@+1 {{previous declaration is here}} +//expected-note@+1 {{previous definition is here}} int __attribute__((target_version("sha3 + pmull "))) foo(void) { return 1; } +//expected-note@-1 {{previous definition is here}} -//expected-error@+1 {{multiversioning attributes cannot be combined}} +//expected-error@+1 {{redefinition of 'foo'}} int __attribute__((target("dotprod"))) foo(void) { return -1; } +//expected-warning@-1 {{attribute declaration must precede definition}} //expected-error@+1 {{redefinition of 'foo'}} int foo(void) { return 2; } +//expected-note@+1 {{previous definition is here}} +__attribute__ ((target("bf16,sve,sve2,dotprod"))) int func(void) { return 1; } +//expected-error@+1 {{redefinition of 'func'}} +__attribute__ ((target("default"))) int func(void) { return 0; } + //expected-note@+1 {{previous declaration is here}} void __attribute__((target_version("bti+flagm2"))) one(void) {} //expected-error@+1 {{multiversioned function redeclarations require identical target attributes}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits