https://gcc.gnu.org/g:5abac04ffc7cc877ff5e1fa6562923b7b05b8289

commit r16-2066-g5abac04ffc7cc877ff5e1fa6562923b7b05b8289
Author: Alfie Richards <alfie.richa...@arm.com>
Date:   Thu Feb 13 15:59:43 2025 +0000

    c++: Fix FMV return type ambiguation
    
    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.

Diff:
---
 gcc/cp/decl.cc                              |  6 ++++--
 gcc/testsuite/g++.target/aarch64/pr119498.C | 19 +++++++++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 83c8e283b56a..be26bd39b225 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -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
index 000000000000..03f1659068dc
--- /dev/null
+++ b/gcc/testsuite/g++.target/aarch64/pr119498.C
@@ -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" } */

Reply via email to