public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8196] c++: Prevent overwriting arguments when merging duplicates [PR112588]
@ 2024-01-17 23:48 Nathaniel Shead
  0 siblings, 0 replies; only message in thread
From: Nathaniel Shead @ 2024-01-17 23:48 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:3471a61ed0ddef70de8f1bbba85cd1e945fc86fd

commit r14-8196-g3471a61ed0ddef70de8f1bbba85cd1e945fc86fd
Author: Nathaniel Shead <nathanieloshead@gmail.com>
Date:   Sat Dec 16 21:34:45 2023 +1100

    c++: Prevent overwriting arguments when merging duplicates [PR112588]
    
    When merging duplicate instantiations of function templates, currently
    read_function_def overwrites the arguments with that of the existing
    duplicate. This is problematic, however, since this means that the
    PARM_DECLs in the body of the function definition no longer match with
    the PARM_DECLs in the argument list, which causes issues when it comes
    to generating RTL.
    
    There doesn't seem to be any reason to do this replacement, so this
    patch removes that logic.
    
            PR c++/112588
    
    gcc/cp/ChangeLog:
    
            * module.cc (trees_in::read_function_def): Don't overwrite
            arguments.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/modules/merge-16.h: New test.
            * g++.dg/modules/merge-16_a.C: New test.
            * g++.dg/modules/merge-16_b.C: New test.
    
    Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>

Diff:
---
 gcc/cp/module.cc                          |  2 --
 gcc/testsuite/g++.dg/modules/merge-16.h   | 10 ++++++++++
 gcc/testsuite/g++.dg/modules/merge-16_a.C |  7 +++++++
 gcc/testsuite/g++.dg/modules/merge-16_b.C |  5 +++++
 4 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 350ad15dc62..8db662c0267 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -11703,8 +11703,6 @@ trees_in::read_function_def (tree decl, tree maybe_template)
       DECL_RESULT (decl) = result;
       DECL_INITIAL (decl) = initial;
       DECL_SAVED_TREE (decl) = saved;
-      if (maybe_dup)
-	DECL_ARGUMENTS (decl) = DECL_ARGUMENTS (maybe_dup);
 
       if (context)
 	SET_DECL_FRIEND_CONTEXT (decl, context);
diff --git a/gcc/testsuite/g++.dg/modules/merge-16.h b/gcc/testsuite/g++.dg/modules/merge-16.h
new file mode 100644
index 00000000000..fdb38551103
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/merge-16.h
@@ -0,0 +1,10 @@
+// PR c++/112588
+
+void f(int*);
+
+template <typename T>
+struct S {
+  void g(int n) { f(&n); }
+};
+
+template struct S<void>;
diff --git a/gcc/testsuite/g++.dg/modules/merge-16_a.C b/gcc/testsuite/g++.dg/modules/merge-16_a.C
new file mode 100644
index 00000000000..c243224c875
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/merge-16_a.C
@@ -0,0 +1,7 @@
+// PR c++/112588
+// { dg-additional-options "-fmodules-ts" }
+// { dg-module-cmi merge16 }
+
+module;
+#include "merge-16.h"
+export module merge16;
diff --git a/gcc/testsuite/g++.dg/modules/merge-16_b.C b/gcc/testsuite/g++.dg/modules/merge-16_b.C
new file mode 100644
index 00000000000..8c7b1f0511f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/merge-16_b.C
@@ -0,0 +1,5 @@
+// PR c++/112588
+// { dg-additional-options "-fmodules-ts" }
+
+#include "merge-16.h"
+import merge16;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-17 23:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-17 23:48 [gcc r14-8196] c++: Prevent overwriting arguments when merging duplicates [PR112588] Nathaniel Shead

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).