This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] Fix mangling ABI breakage (PR c++/39095)


Hi!

The
http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=140916
change broke mangling of operator->.  The following patch fixes it.
Bootstrapped/regtested on x86_64-linux and i686-linux.

2009-02-04  Jakub Jelinek  <jakub@redhat.com>

	PR c++/39095
	* operators.def: Use COMPONENT_REF code for ->/pt operator again,
	remove ./dt operator.
	* mangle.c (write_expression): Handle COMPONENT_REF after handling
	ADDR_EXPR, for COMPONENT_REF without ARROW_EXPR inside of it
	write_string ("dt") instead of using operators.def.

	* g++.dg/abi/mangle31.C: New test.

--- gcc/cp/operators.def.jj	2008-10-23 13:21:09.000000000 +0200
+++ gcc/cp/operators.def	2009-02-04 14:40:33.000000000 +0100
@@ -125,8 +125,7 @@ DEF_SIMPLE_OPERATOR ("&&", TRUTH_ANDIF_E
 DEF_SIMPLE_OPERATOR ("||", TRUTH_ORIF_EXPR, "oo", 2)
 DEF_SIMPLE_OPERATOR (",", COMPOUND_EXPR, "cm", 2)
 DEF_SIMPLE_OPERATOR ("->*", MEMBER_REF, "pm", 2)
-DEF_SIMPLE_OPERATOR ("->", ARROW_EXPR, "pt", 2)
-DEF_SIMPLE_OPERATOR (".", COMPONENT_REF, "dt", 2)
+DEF_SIMPLE_OPERATOR ("->", COMPONENT_REF, "pt", 2)
 DEF_SIMPLE_OPERATOR ("[]", ARRAY_REF, "ix", 2)
 DEF_SIMPLE_OPERATOR ("++", POSTINCREMENT_EXPR, "pp", 2)
 DEF_SIMPLE_OPERATOR ("--", POSTDECREMENT_EXPR, "mm", 2)
--- gcc/cp/mangle.c.jj	2009-01-13 18:32:14.000000000 +0100
+++ gcc/cp/mangle.c	2009-02-04 14:42:00.000000000 +0100
@@ -2298,20 +2299,6 @@ write_expression (tree expr)
 	    write_template_args (template_args);
 	}
     }
-  else if (code == COMPONENT_REF)
-    {
-      tree ob = TREE_OPERAND (expr, 0);
-
-      if (TREE_CODE (ob) == ARROW_EXPR)
-	{
-	  code = ARROW_EXPR;
-	  ob = TREE_OPERAND (ob, 0);
-	}
-
-      write_string (operator_name_info[(int)code].mangled_name);
-      write_expression (ob);
-      write_member_name (TREE_OPERAND (expr, 1));
-    }
   else
     {
       int i;
@@ -2334,6 +2321,23 @@ write_expression (tree expr)
 	  code = TREE_CODE (expr);
 	}
 
+      if (code == COMPONENT_REF)
+	{
+	  tree ob = TREE_OPERAND (expr, 0);
+
+	  if (TREE_CODE (ob) == ARROW_EXPR)
+	    {
+	      write_string (operator_name_info[(int)code].mangled_name);
+	      ob = TREE_OPERAND (ob, 0);
+	    }
+	  else
+	    write_string ("dt");
+
+	  write_expression (ob);
+	  write_member_name (TREE_OPERAND (expr, 1));
+	  return;
+	}
+
       /* If it wasn't any of those, recursively expand the expression.  */
       write_string (operator_name_info[(int) code].mangled_name);
 
--- gcc/testsuite/g++.dg/abi/mangle31.C.jj	2009-02-04 14:48:35.000000000 +0100
+++ gcc/testsuite/g++.dg/abi/mangle31.C	2009-02-04 14:48:58.000000000 +0100
@@ -0,0 +1,35 @@
+// PR c++/39095
+// { dg-do compile }
+
+struct B
+{
+  int b;
+};
+
+struct A
+{
+  B *operator->();
+  A ();
+  B b;
+};
+
+A::A ()
+{
+}
+
+B *
+A::operator->()
+{
+  return &b;
+}
+
+A a;
+
+int
+foo ()
+{
+  return a->b;
+}
+
+// { dg-final { scan-assembler "_ZN1AptEv" } }
+// { dg-final { scan-assembler-not "_ZN1AdtEv" } }

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]