public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/6057: expression mangling doesn't work for operator new
@ 2002-09-13  9:46 Richard Smith
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Smith @ 2002-09-13  9:46 UTC (permalink / raw)
  To: mmitchel; +Cc: gcc-prs

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
 
 
 
 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c++/6057: expression mangling doesn't work for operator new
@ 2002-09-13  7:28 nathan
  0 siblings, 0 replies; 4+ messages in thread
From: nathan @ 2002-09-13  7:28 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, mmitchel, richard

Synopsis: expression mangling doesn't work for operator new

State-Changed-From-To: open->feedback
State-Changed-By: nathan
State-Changed-When: Fri Sep 13 07:28:17 2002
State-Changed-Why:
    is this fixed now?

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6057


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c++/6057: expression mangling doesn't work for operator new
@ 2002-03-26 10:40 mmitchel
  0 siblings, 0 replies; 4+ messages in thread
From: mmitchel @ 2002-03-26 10:40 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, mmitchel, nobody, richard

Synopsis: expression mangling doesn't work for operator new

Responsible-Changed-From-To: unassigned->mmitchel
Responsible-Changed-By: mmitchel
Responsible-Changed-When: Tue Mar 26 10:40:00 2002
Responsible-Changed-Why:
    I will work on a fix and/or incorporate the patch 
    submitted.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6057


^ permalink raw reply	[flat|nested] 4+ messages in thread

* c++/6057: expression mangling doesn't work for operator new
@ 2002-03-26  2:16 richard
  0 siblings, 0 replies; 4+ messages in thread
From: richard @ 2002-03-26  2:16 UTC (permalink / raw)
  To: gcc-gnats


>Number:         6057
>Category:       c++
>Synopsis:       expression mangling doesn't work for operator new
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          ice-on-legal-code
>Submitter-Id:   net
>Arrival-Date:   Tue Mar 26 02:16:05 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Richard Smith
>Release:        3.0.3 and 3.1 branch
>Organization:
>Environment:
linux
>Description:
The code below produces an ICE in write_expression() in 
cp/mangle.c whilst trying to mangle 

  helper< sizeof(new T) >

(or more specifically, the new part of it).  The NEW_EXPR 
tree node takes three parameters: the placement list (NULL
in this example), the type declarator (a 
template_type_parm corresponding to T), and an initializer 
list (also NULL in this case).  The segfault occurs when 
it attempts to recursively call write_expression on the 
NULL placement list.

I've looked in the draft Itanium ABI on the codesourcery 
web page and this gives no guidance as to how this should 
be handled.

I have attached a patch which fixes the problem by mangling calls to
new and new[], schematically, as

  <expression> 
    ::= <new operator-name> <placement expression-list>
                <type> <initializer expression-list>

  <expression-list> ::= <expression>+ _

I'm not particularly keen on this mangling of 
<expression-list> -- I'd prefer something like [random 
lettter] <expression>+ E, but this syntax doesn't take any 
new letters, and uses '_' consistently with, say,
<array-type>.

The same problem occurs with function calls, although my 
patch doesn't address this.  It wouldn't surprise me if 
there wasn't a similar problem with delete and delete[], 
but I haven't yet been able to coax the compiler into 
attempting to mangle either of these.

I have *not* run a complete bootstrap with the patch, nor 
run the test-suite with this patch applied.
>How-To-Repeat:
  template <unsigned int> struct helper {};
  template <class T> 
  static void check( helper<sizeof(new T)> * );
  int main() { check<int>(0); }
>Fix:
--- mangle.c    Fri Mar 22 18:58:01 2002
+++ mangle-patched.c    Fri Mar 22 18:57:42 2002
@@ -173,6 +173,7 @@ static void write_bare_function_type PAR
 static void write_method_parms PARAMS ((tree, int, tree));
 static void write_class_enum_type PARAMS ((tree));
 static void write_template_args PARAMS ((tree));
+static void write_expression_list PARAMS ((tree));
 static void write_expression PARAMS ((tree));
 static void write_template_arg_literal PARAMS ((tree));
 static void write_template_arg PARAMS ((tree));
@@ -1766,6 +1767,21 @@ write_template_args (args)
   write_char ('E');
 }
 
+/* <expression-list> ::= <expression>+ _ */
+
+static void 
+write_expression_list (expr_list) 
+     tree expr_list;
+{
+  while (expr_list)
+    {
+      write_expression (TREE_VALUE (expr_list));
+      expr_list = TREE_CHAIN (expr_list);
+    }
+  
+  write_char ('_');
+}
+
 /* <expression> ::= <unary operator-name> <expression>
                ::= <binary operator-name> <expression> <expression>
                ::= <expr-primary>
@@ -1854,6 +1870,13 @@ write_expression (expr)
        case CONST_CAST_EXPR:
          write_type (TREE_TYPE (expr));
          write_expression (TREE_OPERAND (expr, 0));
+         break;
+
+       case NEW_EXPR:
+       case VEC_NEW_EXPR:
+         write_expression_list (TREE_OPERAND (expr, 0));
+         write_type (TREE_OPERAND (expr, 1));
+         write_expression_list (TREE_OPERAND (expr, 2));
          break;
 
        /* Handle pointers-to-members specially.  */
>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-09-13 16:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-13  9:46 c++/6057: expression mangling doesn't work for operator new Richard Smith
  -- strict thread matches above, loose matches on Subject: below --
2002-09-13  7:28 nathan
2002-03-26 10:40 mmitchel
2002-03-26  2:16 richard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).