This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/6057: expression mangling doesn't work for operator new
- From: Richard Smith <richard at ex-parrot dot com>
- To: mmitchel at gcc dot gnu dot org
- Cc: gcc-prs at gcc dot gnu dot org,
- Date: 13 Sep 2002 16:46:02 -0000
- Subject: Re: c++/6057: expression mangling doesn't work for operator new
- Reply-to: Richard Smith <richard at ex-parrot dot com>
The following reply was made to PR c++/6057; it has been noted by GNATS.
From: Richard Smith <richard@ex-parrot.com>
To: <nathan@gcc.gnu.org>, <gcc-bugs@gcc.gnu.org>, <gcc-prs@gcc.gnu.org>,
<mmitchel@gcc.gnu.org>, <richard@ex-parrot.com>,
<gcc-gnats@gcc.gnu.org>
Cc:
Subject: Re: c++/6057: expression mangling doesn't work for operator new
Date: Fri, 13 Sep 2002 17:45:49 +0100 (BST)
On 13 Sep 2002 nathan@gcc.gnu.org wrote:
> is this fixed now?
No, the bug is still there in cvs on the mainline. Try, for example,
compiling the following code
template <unsigned int> struct helper {};
template <class T> static void check( helper< sizeof( new T ) > * );
int main()
{
check<int>(0);
}
The problem was with the new expression, not the sizeof expression.
There was an unrelated bug with mangling of sizeof expression, which has
now been fixed (can't find PR number at the moment); but that only applied
where the argument of the sizeof expression was a type that was dependent
on a template parameter, not an expression.
The segfault is actually occuring on the line
code = TREE_CODE (expr); // Line 1790 in revision 1.57
at the start of write_expression in mangle.c because expr is
a NULL pointer. This is happening because when write_expression is called
to write the NEW_EXPR it goes down the 'default' case statement at the end
of the function, and iterates over each of the tree operands. The three
operands to the NEW_EXPR tree node are the placement expresion (which is
of type TREE_LIST, or, more frequently a NULL pointer), the type which is
being created (which is a type not an expression), and the initialiser
list (again, of type TREE_LIST, or a NULL pointer).
The second operand of the NEW_EXPR needs to have write_type, not
write_expression called on it; the first and third operands of NEW_EXPR
need to be mangled in some new way, which is what the
write_expression_list function in my patch does (it also copes with a
NULL pointer argument, which write_expression doesn't).
The following test case showes the other failure modes of the existing
code
struct foo {} f;
typedef unsigned int size_t;
void *operator new( size_t, foo );
template <unsigned int> struct helper {};
template <class T> static void check( helper< sizeof( new(f) T(0) ) > * );
int main()
{
check<int>(0);
}
where the segfault occurs because write_expression can't cope being passed
a TREE_LIST.
As I mentioned in the original PR, a more general solution would be
preferable: I know that the same problems apply to function calls,
template <class T> T make_type();
template <unsigned int> struct helper {};
template <class T> static void check( helper< sizeof( make_type<T>() ) > * );
int main()
{
check<int>(0);
}
where the segfault occurs because CALL_EXPR's operands can't be handled.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6057
--
Richard Smith