Patchwork C++ PATCH to mangling of 'new auto'

login
register
mail settings
Submitter Jason Merrill
Date March 21, 2012, 4:04 a.m.
Message ID <4F695342.5020208@redhat.com>
Download mbox | patch
Permalink /patch/147906/
State New
Headers show

Comments

Jason Merrill - March 21, 2012, 4:04 a.m.
GCC 4.7 adds mangling for new-expressions in a function signature, but I 
now notice it produces wrong mangling for 'new auto' in simple cases. 
This patch fixes it.

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

This also seems like it might be a candidate for 4.7.0.  What do you 
think, Jakub?
Jakub Jelinek - March 21, 2012, 11:27 a.m.
On Wed, Mar 21, 2012 at 12:04:18AM -0400, Jason Merrill wrote:
> This also seems like it might be a candidate for 4.7.0.  What do you
> think, Jakub?

Ok for 4.7.0. 

	Jakub

Patch

commit 96472bd7b10415d61a3d5e0d640825baf80eb576
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Mar 7 19:28:34 2012 -0500

    gcc/cp/
    	* mangle.c (write_type): Handle 'auto'.
    	* init.c (build_new): Don't do auto deduction where it might
    	affect template mangling.
    libiberty/
    	* cp-demangle.c (cplus_demangle_type): Handle 'auto'.

diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 1b2a1ef..bcb5ab7 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -2774,7 +2774,9 @@  build_new (VEC(tree,gc) **placement, tree type, tree nelts,
   if (type == error_mark_node)
     return error_mark_node;
 
-  if (nelts == NULL_TREE && VEC_length (tree, *init) == 1)
+  if (nelts == NULL_TREE && VEC_length (tree, *init) == 1
+      /* Don't do auto deduction where it might affect mangling.  */
+      && (!processing_template_decl || at_function_scope_p ()))
     {
       tree auto_node = type_uses_auto (type);
       if (auto_node)
diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index 5d6beb5..1536828 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -1933,6 +1933,13 @@  write_type (tree type)
 	      break;
 
 	    case TEMPLATE_TYPE_PARM:
+	      if (is_auto (type))
+		{
+		  write_identifier ("Da");
+		  ++is_builtin_type;
+		  break;
+		}
+	      /* else fall through.  */
 	    case TEMPLATE_PARM_INDEX:
 	      write_template_param (type);
 	      break;
diff --git a/gcc/testsuite/g++.dg/cpp0x/auto32.C b/gcc/testsuite/g++.dg/cpp0x/auto32.C
new file mode 100644
index 0000000..2aad34e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/auto32.C
@@ -0,0 +1,9 @@ 
+// { dg-do compile { target c++11 } }
+
+// { dg-final { scan-assembler "_Z1fIiEDTnw_Dapifp_EET_" } }
+template <class T> auto f(T t) -> decltype (new auto(t));
+
+int main()
+{
+  f(1);
+}
diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index 2b3d182..d95b56c 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -2270,6 +2270,11 @@  cplus_demangle_type (struct d_info *di)
 			     cplus_demangle_type (di), NULL);
 	  can_subst = 1;
 	  break;
+
+	case 'a':
+	  /* auto */
+	  ret = d_make_name (di, "auto", 4);
+	  break;
 	  
 	case 'f':
 	  /* 32-bit decimal floating point */
diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected
index 036c481..d489692 100644
--- a/libiberty/testsuite/demangle-expected
+++ b/libiberty/testsuite/demangle-expected
@@ -4075,6 +4075,12 @@  decltype (new int{}) f1<int>(int)
 --format=gnu-v3
 _Zli2_wPKc
 operator"" _w(char const*)
+--format=gnu-v3
+_Z1fIiEDTnw_Dapifp_EET_
+decltype (new auto({parm#1})) f<int>(int)
+--format=gnu-v3
+_Z1fIiERDaRKT_S1_
+auto& f<int>(int const&, int)
 #
 # Ada (GNAT) tests.
 #