[PATCH] D133641: [Clang] [Sema] Ignore invalid multiversion function redeclarations

Evgeny Shulgin via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 13 13:12:23 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG67f08bf1bfa8: [Clang] [Sema] Ignore invalid multiversion function redeclarations (authored by Izaron).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133641/new/

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
@@ -11082,11 +11082,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.459854.patch
Type: text/x-patch
Size: 1720 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220913/75cf7b49/attachment.bin>


More information about the cfe-commits mailing list