This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: internal compiler error
- To: lsh@lsh.cs.brown.edu
- Subject: Re: internal compiler error
- From: Mark Mitchell <mark@codesourcery.com>
- Date: Mon, 30 Aug 1999 12:00:17 -0700
- Cc: gcc-patches@gcc.gnu.org
- Organization: CodeSourcery, LLC
- References: <199908300702.DAA02920@lsh.cs.brown.edu>
Thanks for your report. This is fixed with the attached patch.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
1999-08-30 Mark Mitchell <mark@codesourcery.com>
* cp-tree.h (begin_init_stmts): Declare.
(finish_init_stmts): Likewise.
* cvt.c (build_up_reference): Wrap the declaration of a temporary
in a statement-expression so that we will see it when expanding
tree structure later.
* init.c (begin_init_stmts): Don't make it static.
(finish_init_stmts): Likewise.
Index: testsuite/g++.old-deja/g++.pt/crash53.C
===================================================================
RCS file: crash53.C
diff -N crash53.C
*** /dev/null Sat Dec 5 20:30:03 1998
--- crash53.C Mon Aug 30 11:48:42 1999
***************
*** 0 ****
--- 1,16 ----
+ // Build don't link:
+ // Origin: Mark Mitchell <mark@codesourcery.com>
+
+ struct S
+ {
+ };
+
+ S g ();
+
+ template <class T>
+ void f ()
+ {
+ const S& s = g ();
+ }
+
+ template void f<int>();
Index: cp/cp-tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.278
diff -c -p -r1.278 cp-tree.h
*** cp-tree.h 1999/08/30 15:50:27 1.278
--- cp-tree.h 1999/08/30 18:48:45
*************** extern tree build_delete PROTO((tree,
*** 3129,3134 ****
--- 3129,3136 ----
extern tree build_vbase_delete PROTO((tree, tree));
extern tree build_vec_delete PROTO((tree, tree, tree, tree, int));
extern tree create_temporary_var PROTO((tree));
+ extern void begin_init_stmts PROTO((tree *, tree *));
+ extern tree finish_init_stmts PROTO((tree, tree));
/* in input.c */
Index: cp/cvt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cvt.c,v
retrieving revision 1.63
diff -c -p -r1.63 cvt.c
*** cvt.c 1999/08/11 20:22:25 1.63
--- cvt.c 1999/08/30 18:48:46
*************** build_up_reference (type, arg, flags)
*** 339,349 ****
--- 339,353 ----
tree rval;
tree argtype = TREE_TYPE (arg);
tree target_type = TREE_TYPE (type);
+ tree stmt_expr = NULL_TREE;
my_friendly_assert (TREE_CODE (type) == REFERENCE_TYPE, 187);
if ((flags & DIRECT_BIND) && ! real_lvalue_p (arg))
{
+ tree compound_stmt;
+
+ /* Create a new temporary variable. */
tree targ = arg;
if (toplevel_bindings_p ())
arg = get_temp_name (argtype, 1);
*************** build_up_reference (type, arg, flags)
*** 351,360 ****
--- 355,379 ----
{
arg = pushdecl (build_decl (VAR_DECL, NULL_TREE, argtype));
DECL_ARTIFICIAL (arg) = 1;
+ /* Generate code to initialize it. We wrap it in a
+ statement-expression so that when we are building a
+ statement-tree we will have a representation of this
+ declaration. */
+ begin_init_stmts (&stmt_expr, &compound_stmt);
}
+
+ /* Process the initializer for the declaration. */
DECL_INITIAL (arg) = targ;
cp_finish_decl (arg, targ, NULL_TREE, 0,
LOOKUP_ONLYCONVERTING|DIRECT_BIND);
+
+ /* And wrap up the statement-expression, if necessary. */
+ if (!toplevel_bindings_p ())
+ {
+ if (building_stmt_tree ())
+ add_decl_stmt (arg);
+ stmt_expr = finish_init_stmts (stmt_expr, compound_stmt);
+ }
}
else if (!(flags & DIRECT_BIND) && ! lvalue_p (arg))
{
*************** build_up_reference (type, arg, flags)
*** 389,394 ****
--- 408,420 ----
= convert_to_pointer_force (build_pointer_type (target_type), rval);
rval = build1 (NOP_EXPR, type, rval);
TREE_CONSTANT (rval) = TREE_CONSTANT (TREE_OPERAND (rval, 0));
+
+ /* If we created and initialized a new temporary variable, add the
+ representation of that initialization to the RVAL. */
+ if (stmt_expr)
+ rval = build (COMPOUND_EXPR, TREE_TYPE (rval), stmt_expr, rval);
+
+ /* And return the result. */
return rval;
}
Index: cp/init.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/init.c,v
retrieving revision 1.123
diff -c -p -r1.123 init.c
*** init.c 1999/08/29 19:03:29 1.123
--- init.c 1999/08/30 18:48:56
*************** static tree initializing_context PROTO((
*** 60,67 ****
static tree build_java_class_ref PROTO((tree));
static void expand_cleanup_for_base PROTO((tree, tree));
static tree get_temp_regvar PROTO((tree, tree));
- static void begin_init_stmts PROTO((tree *, tree *));
- static tree finish_init_stmts PROTO((tree, tree));
/* Cache the identifier nodes for the magic field of a new cookie. */
static tree nc_nelts_field_id;
--- 60,65 ----
*************** expand_member_init (exp, name, init)
*** 1007,1013 ****
pass them back to finish_init_stmts when the expression is
complete. */
! static void
begin_init_stmts (stmt_expr_p, compound_stmt_p)
tree *stmt_expr_p;
tree *compound_stmt_p;
--- 1005,1011 ----
pass them back to finish_init_stmts when the expression is
complete. */
! void
begin_init_stmts (stmt_expr_p, compound_stmt_p)
tree *stmt_expr_p;
tree *compound_stmt_p;
*************** begin_init_stmts (stmt_expr_p, compound_
*** 1020,1026 ****
/* Finish out the statement-expression begun by the previous call to
begin_init_stmts. Returns the statement-expression itself. */
! static tree
finish_init_stmts (stmt_expr, compound_stmt)
tree stmt_expr;
tree compound_stmt;
--- 1018,1024 ----
/* Finish out the statement-expression begun by the previous call to
begin_init_stmts. Returns the statement-expression itself. */
! tree
finish_init_stmts (stmt_expr, compound_stmt)
tree stmt_expr;
tree compound_stmt;