]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cp-demangle.c (cplus_demangle_operators): Add *_cast.
authorJason Merrill <jason@redhat.com>
Wed, 18 Jul 2012 19:51:36 +0000 (15:51 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 18 Jul 2012 19:51:36 +0000 (15:51 -0400)
* cp-demangle.c (cplus_demangle_operators): Add *_cast.
(op_is_new_cast): New.
(d_expression, d_print_comp): Check it.

From-SVN: r189630

gcc/testsuite/g++.dg/abi/mangle3-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/abi/mangle3.C
gcc/testsuite/g++.dg/debug/nullptr01.C
libiberty/ChangeLog
libiberty/cp-demangle.c
libiberty/testsuite/demangle-expected

diff --git a/gcc/testsuite/g++.dg/abi/mangle3-2.C b/gcc/testsuite/g++.dg/abi/mangle3-2.C
new file mode 100644 (file)
index 0000000..ac85fb0
--- /dev/null
@@ -0,0 +1,20 @@
+// Test mangling of type casts
+// { dg-options "-fabi-version=0" }
+// { dg-do compile }
+
+template<int i> class A {};
+template<bool b> class B {};
+
+template<int i> void f(A<i> &, B<bool(i)> &) {}
+template<int i> void g(A<i> &, B<static_cast<bool>(i)> &) {}
+
+int main()
+{
+  A<1> a;
+  B<true> b;
+  f(a, b);
+  g(a, b);
+}
+
+// { dg-final { scan-assembler "\n_?_Z1fILi1EEvR1AIXT_EER1BIXcvbT_EE\[: \t\n\]" } }
+// { dg-final { scan-assembler "\n_?_Z1gILi1EEvR1AIXT_EER1BIXscbT_EE\[: \t\n\]" } }
index a20b877f477bd97747e0ade6746a97217b2195c6..5f44f767732d36e041939d75dcd286da1130b672 100644 (file)
@@ -1,4 +1,5 @@
 // Test mangling of type casts
+// { dg-options "-fabi-version=2" }
 // { dg-do compile }
 
 template<int i> class A {};
index ab08588f2ba6b5835af47869c093bb1598de1740..63c16ac8f0e65c486aa3e1b8089bdef020412fe6 100644 (file)
@@ -1,5 +1,5 @@
 // Test that debugging backends don't crash on NULLPTR_TYPE.
-// { dg-options "-std=c++0x" }
+// { dg-options "-std=c++0x -fabi-version=0" }
 
 typedef decltype(nullptr) nullptr_t;
 
@@ -12,4 +12,4 @@ template <> nullptr_t g(A<nullptr_t>)
   nullptr_t local;
 }
 // { dg-final { scan-assembler "_Z1fDn" } }
-// { dg-final { scan-assembler "_Z1gI1AIDnEES1_T_" } }
+// { dg-final { scan-assembler "_Z1gI1AIDnEEDnT_" } }
index 4ece5ab7474cf34c750fa7306a1daf7951b04d64..716a2ce9d235ba0c7cbfde6c1eb95a0e627f0f46 100644 (file)
@@ -1,3 +1,9 @@
+2012-07-18  Jason Merrill  <jason@redhat.com>
+
+       * cp-demangle.c (cplus_demangle_operators): Add *_cast.
+       (op_is_new_cast): New.
+       (d_expression, d_print_comp): Check it.
+
 2012-07-13  Doug Evans  <dje@google.com>
 
        * filename_cmp.c (filename_hash, filename_eq): New functions.
index 27cc323f2a24c03c584e8ec74961d9d92e5e49b0..258aaa715504a293a677cc5d087b4929855a6bdf 100644 (file)
@@ -1582,11 +1582,13 @@ const struct demangle_operator_info cplus_demangle_operators[] =
   { "an", NL ("&"),         2 },
   { "at", NL ("alignof "),   1 },
   { "az", NL ("alignof "),   1 },
+  { "cc", NL ("const_cast"), 2 },
   { "cl", NL ("()"),        2 },
   { "cm", NL (","),         2 },
   { "co", NL ("~"),         1 },
   { "dV", NL ("/="),        2 },
   { "da", NL ("delete[] "), 1 },
+  { "dc", NL ("dynamic_cast"), 2 },
   { "de", NL ("*"),         1 },
   { "dl", NL ("delete "),   1 },
   { "ds", NL (".*"),        2 },
@@ -1626,8 +1628,10 @@ const struct demangle_operator_info cplus_demangle_operators[] =
   { "qu", NL ("?"),         3 },
   { "rM", NL ("%="),        2 },
   { "rS", NL (">>="),       2 },
+  { "rc", NL ("reinterpret_cast"), 2 },
   { "rm", NL ("%"),         2 },
   { "rs", NL (">>"),        2 },
+  { "sc", NL ("static_cast"), 2 },
   { "st", NL ("sizeof "),   1 },
   { "sz", NL ("sizeof "),   1 },
   { "tr", NL ("throw"),     0 },
@@ -2809,6 +2813,18 @@ d_exprlist (struct d_info *di, char terminator)
   return list;
 }
 
+/* Returns nonzero iff OP is an operator for a C++ cast: const_cast,
+   dynamic_cast, static_cast or reinterpret_cast.  */
+
+static int
+op_is_new_cast (struct demangle_component *op)
+{
+  const char *code = op->u.s_operator.op->code;
+  return (code[1] == 'c'
+         && (code[0] == 's' || code[0] == 'd'
+             || code[0] == 'c' || code[0] == 'r'));
+}
+
 /* <expression> ::= <(unary) operator-name> <expression>
                 ::= <(binary) operator-name> <expression> <expression>
                 ::= <(trinary) operator-name> <expression> <expression> <expression>
@@ -2971,7 +2987,10 @@ d_expression (struct d_info *di)
            struct demangle_component *left;
            struct demangle_component *right;
 
-           left = d_expression (di);
+           if (op_is_new_cast (op))
+             left = cplus_demangle_type (di);
+           else
+             left = d_expression (di);
            if (!strcmp (code, "cl"))
              right = d_exprlist (di, 'E');
            else if (!strcmp (code, "dt") || !strcmp (code, "pt"))
@@ -4455,6 +4474,17 @@ d_print_comp (struct d_print_info *dpi, int options,
          return;
        }
 
+      if (op_is_new_cast (d_left (dc)))
+       {
+         d_print_expr_op (dpi, options, d_left (dc));
+         d_append_char (dpi, '<');
+         d_print_comp (dpi, options, d_left (d_right (dc)));
+         d_append_string (dpi, ">(");
+         d_print_comp (dpi, options, d_right (d_right (dc)));
+         d_append_char (dpi, ')');
+         return;
+       }
+
       /* We wrap an expression which uses the greater-than operator in
         an extra layer of parens so that it does not get confused
         with the '>' which ends the template parameters.  */
index 58c1368187754e4993d111f2e1a4a7d9ab97c105..6b55d30298e54250e9988c5ca50282283894d1a1 100644 (file)
@@ -4081,6 +4081,9 @@ decltype (new auto({parm#1})) f<int>(int)
 --format=gnu-v3
 _Z1fIiERDaRKT_S1_
 auto& f<int>(int const&, int)
+--format=gnu-v3
+_Z1gILi1EEvR1AIXT_EER1BIXscbT_EE
+void g<1>(A<1>&, B<static_cast<bool>(1)>&)
 #
 # Ada (GNAT) tests.
 #