diff mbox

C++ PATCH for c++/51827 (mangling error with PCH and LTO)

Message ID 4F1496D1.4090502@redhat.com
State New
Headers show

Commit Message

Jason Merrill Jan. 16, 2012, 9:29 p.m. UTC
When outputting PCH/LTO, the compiler tries to generate mangled names 
for all decls before discarding language-specific data.  But that 
doesn't make sense for templates, and leads to conflicts in this case. 
Fixed by refusing to mangle templates.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit f984ce6e04c376a9eb7a2a69706489f5aa330573
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Jan 16 14:19:32 2012 -0500

    	PR c++/51827
    	* mangle.c (mangle_decl): Don't mangle uninstantiated templates.

diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index 5f2fa15..15b1aca 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -3330,7 +3330,21 @@  get_mangled_id (tree decl)
 void
 mangle_decl (const tree decl)
 {
-  tree id = get_mangled_id (decl);
+  tree id;
+  bool dep;
+
+  /* Don't bother mangling uninstantiated templates.  */
+  ++processing_template_decl;
+  if (TREE_CODE (decl) == TYPE_DECL)
+    dep = dependent_type_p (TREE_TYPE (decl));
+  else
+    dep = (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)
+	   && any_dependent_template_arguments_p (DECL_TI_ARGS (decl)));
+  --processing_template_decl;
+  if (dep)
+    return;
+
+  id = get_mangled_id (decl);
   SET_DECL_ASSEMBLER_NAME (decl, id);
 
   if (G.need_abi_warning
diff --git a/gcc/testsuite/g++.dg/pch/mangle1.C b/gcc/testsuite/g++.dg/pch/mangle1.C
new file mode 100644
index 0000000..504fa2d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pch/mangle1.C
@@ -0,0 +1,3 @@ 
+// { dg-options -std=c++11 }
+
+#include "mangle1.Hs"
diff --git a/gcc/testsuite/g++.dg/pch/mangle1.Hs b/gcc/testsuite/g++.dg/pch/mangle1.Hs
new file mode 100644
index 0000000..4d48c2e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pch/mangle1.Hs
@@ -0,0 +1,8 @@ 
+// PR c++/51827
+// { dg-options "-flto -std=c++0x" }
+
+template<typename X> struct S { };
+template<typename Y> struct T {
+  template <typename ... A> T(S <A ...>);
+};
+inline void f(T<int>) { }