This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Fix mangling of COMPOUND_EXPR
- From: "Giovanni Bajo" <giovannibajo at libero dot it>
- To: <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 25 Jun 2003 01:22:44 +0200
- Subject: [C++ PATCH] Fix mangling of COMPOUND_EXPR
Hello,
currently, mangle.c is broken with respect to COMPOUND_EXPR. In fact,
COMPOUND_EXPR in templates are generated so that the first operand is a
TREE_LIST which holds the two expressions, while the second operand is a
null tree. This same bug is present in error.c, and it's been fixed by my
(unreviewed) patch:
http://gcc.gnu.org/ml/gcc-patches/2003-06/msg02592.html
With this patch, it's possible to mangle a compound expression correctly, as
specified by the C++ ABI. The testcase check for both the correctness of the
template expression and the mangled name.
This patch has been bootstrapped on i686-pc-cygwin (c, c++, java) and
regtested (with my previous one) with "make check-g++" with no new
regressions. OK for mainline?
Giovanni Bajo
2003-06-25 Giovanni Bajo <giovannibajo@libero.it>
* mangle.c (write_expression): Support the COMPOUND_EXPR
tree layout generated within a template.
2003-06-25 Giovanni Bajo <giovannibajo@libero.it>
* g++.dg/abi/mangle18.C: New test.
Index: mangle.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/cp/mangle.c,v
retrieving revision 1.68
diff -c -w -p -r1.68 mangle.c
*** mangle.c 3 Apr 2003 03:45:48 -0000 1.68
--- mangle.c 24 Jun 2003 22:56:27 -0000
*************** write_expression (expr)
*** 2011,2016 ****
--- 2014,2045 ----
write_encoding (TREE_OPERAND (expr, 1));
}
break;
+
+ case COMPOUND_EXPR:
+ /* A COMPOUND_EXPR within a template has a different layout.
+ Both expressions are stored in a TREE_LIST as the first
+ operand, while the second operand is a null tree. */
+ if (TREE_CODE (TREE_OPERAND (expr, 0)) == TREE_LIST)
+ {
+ tree list = TREE_OPERAND (expr, 0);
+
+ /* The second operand should be empty. */
+ if (TREE_OPERAND (expr, 1))
+ abort();
+
+ write_expression (TREE_VALUE (list));
+ list = TREE_CHAIN (list);
+ write_expression (TREE_VALUE (list));
+ list = TREE_CHAIN (list);
+
+ /* The list should contain only two elements: the two
+ expressions. */
+ if (list)
+ abort();
+
+ break;
+ }
+ /* fall-through! */
default:
for (i = 0; i < TREE_CODE_LENGTH (code); ++i)
// { dg-do compile }
// Check mangling of COMPOUND_EXPR
template <int N>
struct A {};
struct B
{
typedef float foo;
typedef int bar;
};
template <class T>
A<sizeof(T::foo, T::bar)> foo(void)
{}
int main(void)
{
A<sizeof(int)> a = foo<B>();
return 0;
}
// { dg-final { scan-assembler __Z3fooI1BE1AIXszcmsrT_3foosrS2_3barEEv } }