Author: Evgeny Shulgin Date: 2022-09-13T20:12:09Z New Revision: 67f08bf1bfa85fcdc1d91a3e6cce703e94611244
URL: https://github.com/llvm/llvm-project/commit/67f08bf1bfa85fcdc1d91a3e6cce703e94611244 DIFF: https://github.com/llvm/llvm-project/commit/67f08bf1bfa85fcdc1d91a3e6cce703e94611244.diff LOG: [Clang] [Sema] Ignore invalid multiversion function redeclarations If a redeclaration of a multiversion function is invalid, it may be in a broken condition (for example, missing an important attribute). We shouldn't analyze invalid redeclarations. Fixes https://github.com/llvm/llvm-project/issues/57343 Reviewed By: tahonermann Differential Revision: https://reviews.llvm.org/D133641 Added: Modified: clang/lib/Sema/SemaDecl.cpp clang/test/Sema/attr-target-mv.c Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 58774c0fa44a3..e4bd827b38d39 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -11082,11 +11082,11 @@ static bool CheckMultiVersionAdditionalDecl( bool MayNeedOverloadableChecks = AllowOverloadingOfFunction(Previous, S.Context, NewFD); - // Next, check ALL non-overloads to see if this is a redeclaration of a - // previous member of the MultiVersion set. + // Next, check ALL non-invalid non-overloads to see if this is a redeclaration + // of a previous member of the MultiVersion set. for (NamedDecl *ND : Previous) { FunctionDecl *CurFD = ND->getAsFunction(); - if (!CurFD) + if (!CurFD || CurFD->isInvalidDecl()) continue; if (MayNeedOverloadableChecks && S.IsOverload(NewFD, CurFD, UseMemberUsingDeclRules)) diff --git a/clang/test/Sema/attr-target-mv.c b/clang/test/Sema/attr-target-mv.c index b02b13079163b..8218771275e1b 100644 --- a/clang/test/Sema/attr-target-mv.c +++ b/clang/test/Sema/attr-target-mv.c @@ -52,6 +52,15 @@ int __attribute__((target("default"))) redef2(void) { return 1;} // expected-note@-2 {{previous definition is here}} int __attribute__((target("default"))) redef2(void) { return 1;} +int redef3(void) { return 1; } +// expected-warning@+4 {{attribute declaration must precede definition}} +// expected-note@-2 {{previous definition is here}} +// expected-error@+2 {{redefinition of 'redef3'}} +// expected-note@-4 {{previous definition is here}} +int __attribute__((target("default"))) redef3(void) { return 1; } +// allow this, since we don't complain about more than one redefinition +int __attribute__((target("sse4.2"))) redef3(void) { return 1; } + int __attribute__((target("sse4.2"))) mv_after_use(void) { return 1; } int use3(void) { return mv_after_use(); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits