]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix FMV return type ambiguation
authorAlfie Richards <alfie.richards@arm.com>
Thu, 13 Feb 2025 15:59:43 +0000 (15:59 +0000)
committerAlfie Richards <alfie.richards@arm.com>
Mon, 7 Jul 2025 15:20:53 +0000 (15:20 +0000)
Add logic for the case of two FMV annotated functions with identical
signature other than the return type.

Previously this was ignored, this changes the behavior to emit a diagnostic.

gcc/cp/ChangeLog:
PR c++/119498
* decl.cc (duplicate_decls): Change logic to not always exclude FMV
annotated functions in cases of return type non-ambiguation.

gcc/testsuite/ChangeLog:
PR c++/119498
* g++.target/aarch64/pr119498.C: New test.

gcc/cp/decl.cc
gcc/testsuite/g++.target/aarch64/pr119498.C [new file with mode: 0644]

index 83c8e283b56a930d77c9ce949318ec7f75923852..be26bd39b2254a82090c740eb707f6654e986167 100644 (file)
@@ -2014,8 +2014,10 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
            }
          /* For function versions, params and types match, but they
             are not ambiguous.  */
-         else if ((!DECL_FUNCTION_VERSIONED (newdecl)
-                   && !DECL_FUNCTION_VERSIONED (olddecl))
+         else if (((!DECL_FUNCTION_VERSIONED (newdecl)
+                    && !DECL_FUNCTION_VERSIONED (olddecl))
+                   || !same_type_p (fndecl_declared_return_type (newdecl),
+                                    fndecl_declared_return_type (olddecl)))
                   /* Let constrained hidden friends coexist for now, we'll
                      check satisfaction later.  */
                   && !member_like_constrained_friend_p (newdecl)
diff --git a/gcc/testsuite/g++.target/aarch64/pr119498.C b/gcc/testsuite/g++.target/aarch64/pr119498.C
new file mode 100644 (file)
index 0000000..03f1659
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-require-ifunc "" } */
+/* { dg-options "-O0" } */
+/* { dg-additional-options "-Wno-experimental-fmv-target" } */
+
+__attribute__ ((target_version ("default"))) int
+foo ();
+
+__attribute__ ((target_version ("default"))) int
+foo () { return 1; } /* { dg-message "old declaration" } */
+
+__attribute__ ((target_version ("dotprod"))) float
+foo () { return 3; } /* { dg-error "ambiguating new declaration" } */
+
+__attribute__ ((target_version ("sve"))) int
+foo2 () { return 1; } /* { dg-message "old declaration" } */
+
+__attribute__ ((target_version ("dotprod"))) float
+foo2 () { return 3; } /* { dg-error "ambiguating new declaration of" } */