[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
This commit is contained in:
Evgeny Shulgin 2022-09-10 13:36:06 +00:00
parent a8a49923dd
commit 67f08bf1bf
2 changed files with 12 additions and 3 deletions

View File

@ -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))

View File

@ -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();