[PATCH] D133641: [Clang] [Sema] Ignore invalid multiversion function redeclarations
Evgeny Shulgin via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 10 06:46:42 PDT 2022
Izaron created this revision.
Izaron added reviewers: tahonermann, erichkeane.
Herald added a project: All.
Izaron requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
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
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D133641
Files:
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/attr-target-mv.c
Index: clang/test/Sema/attr-target-mv.c
===================================================================
--- clang/test/Sema/attr-target-mv.c
+++ clang/test/Sema/attr-target-mv.c
@@ -52,6 +52,15 @@
// expected-note at -2 {{previous definition is here}}
int __attribute__((target("default"))) redef2(void) { return 1;}
+int redef3(void) { return 1; }
+// expected-warning at +4 {{attribute declaration must precede definition}}
+// expected-note at -2 {{previous definition is here}}
+// expected-error at +2 {{redefinition of 'redef3'}}
+// expected-note at -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();
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -11081,11 +11081,11 @@
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))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133641.459286.patch
Type: text/x-patch
Size: 1720 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220910/73814a8e/attachment.bin>
More information about the cfe-commits
mailing list