c-common.c (statement_code_p): Handle CLEANUP_STMT.
* c-common.c (statement_code_p): Handle CLEANUP_STMT. * c-common.def (CLEANUP_STMT): New tree node. * c-common.h (CLEANUP_DECL): New macro. (CLEANUP_EXPR): Likewise. * c-semantics.c (expand_stmt): Handle CLEANUP_STMT. * tree-dump.c (dequeue_and_dump): Handle CLEANUP_STMT. * tree-inline.c (initialize_inlined_parameters): Clean up new local variables. * cp-tree.h (CLEANUP_DECL): Remove. (CLEANUP_EXPR): Likewise. * decl.c (destroy_local_var): Simplify. (maybe_build_cleanup): Tidy. * dump.c (cp_dump_tree): Remove handling of CLEANUP_STMT. * semantics.c (cp_expand_stmt): Likewise. * cp/tree.c (cp_statement_code_p): Likewise. * g++.dg/opt/dtor1.C: New test. From-SVN: r50830
This commit is contained in:
parent
08bcc159d9
commit
6e4ae815bd
16 changed files with 95 additions and 26 deletions
|
@ -1,3 +1,15 @@
|
|||
2002-03-15 Mark Mitchell <mark@codesourcery.com>
|
||||
|
||||
* c-common.c (statement_code_p): Handle CLEANUP_STMT.
|
||||
* c-common.def (CLEANUP_STMT): New tree node.
|
||||
* c-common.h (CLEANUP_DECL): New macro.
|
||||
(CLEANUP_EXPR): Likewise.
|
||||
* c-semantics.c (expand_stmt): Handle CLEANUP_STMT.
|
||||
* expr.c (expand_expr): Tidy.
|
||||
* tree-dump.c (dequeue_and_dump): Handle CLEANUP_STMT.
|
||||
* tree-inline.c (initialize_inlined_parameters): Clean up
|
||||
new local variables.
|
||||
|
||||
2002-03-15 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
PR bootstrap/4128
|
||||
|
|
|
@ -3213,6 +3213,7 @@ statement_code_p (code)
|
|||
{
|
||||
switch (code)
|
||||
{
|
||||
case CLEANUP_STMT:
|
||||
case EXPR_STMT:
|
||||
case COMPOUND_STMT:
|
||||
case DECL_STMT:
|
||||
|
|
|
@ -113,6 +113,11 @@ DEFTREECODE (STMT_EXPR, "stmt_expr", 'e', 1)
|
|||
the compound literal. */
|
||||
DEFTREECODE (COMPOUND_LITERAL_EXPR, "compound_literal_expr", 'e', 1)
|
||||
|
||||
/* A CLEANUP_STMT marks the point at which a declaration is fully
|
||||
constructed. If, after this point, the CLEANUP_DECL goes out of
|
||||
scope, the CLEANUP_EXPR must be run. */
|
||||
DEFTREECODE (CLEANUP_STMT, "cleanup_stmt", 'e', 2)
|
||||
|
||||
/*
|
||||
Local variables:
|
||||
mode:c
|
||||
|
|
|
@ -693,6 +693,13 @@ extern tree strip_array_types PARAMS ((tree));
|
|||
#define ASM_VOLATILE_P(NODE) \
|
||||
(ASM_CV_QUAL (ASM_STMT_CHECK (NODE)) != NULL_TREE)
|
||||
|
||||
/* The VAR_DECL to clean up in a CLEANUP_STMT. */
|
||||
#define CLEANUP_DECL(NODE) \
|
||||
TREE_OPERAND (CLEANUP_STMT_CHECK (NODE), 0)
|
||||
/* The cleanup to run in a CLEANUP_STMT. */
|
||||
#define CLEANUP_EXPR(NODE) \
|
||||
TREE_OPERAND (CLEANUP_STMT_CHECK (NODE), 1)
|
||||
|
||||
/* The filename we are changing to as of this FILE_STMT. */
|
||||
#define FILE_STMT_FILENAME_NODE(NODE) \
|
||||
(TREE_OPERAND (FILE_STMT_CHECK (NODE), 0))
|
||||
|
|
|
@ -847,6 +847,10 @@ expand_stmt (t)
|
|||
genrtl_scope_stmt (t);
|
||||
break;
|
||||
|
||||
case CLEANUP_STMT:
|
||||
genrtl_decl_cleanup (CLEANUP_DECL (t), CLEANUP_EXPR (t));
|
||||
break;
|
||||
|
||||
default:
|
||||
if (lang_expand_stmt)
|
||||
(*lang_expand_stmt) (t);
|
||||
|
|
|
@ -1,3 +1,13 @@
|
|||
2002-03-15 Mark Mitchell <mark@codesourcery.com>
|
||||
|
||||
* cp-tree.h (CLEANUP_DECL): Remove.
|
||||
(CLEANUP_EXPR): Likewise.
|
||||
* decl.c (destroy_local_var): Simplify.
|
||||
(maybe_build_cleanup): Tidy.
|
||||
* dump.c (cp_dump_tree): Remove handling of CLEANUP_STMT.
|
||||
* semantics.c (cp_expand_stmt): Likewise.
|
||||
* cp/tree.c (cp_statement_code_p): Likewise.
|
||||
|
||||
2002-03-15 Jason Merrill <jason@redhat.com>
|
||||
|
||||
PR c++/5857
|
||||
|
|
|
@ -230,10 +230,6 @@ DEFTREECODE (SUBOBJECT, "subobject", 'e', 1)
|
|||
the cleanups associated with any SUBOBJECT_CLEANUPS need no longer
|
||||
be run. */
|
||||
DEFTREECODE (CTOR_STMT, "ctor_stmt", 'e', 0)
|
||||
/* A CLEANUP_STMT marks the point at which a declaration is fully
|
||||
constructed. If, after this point, the CLEANUP_DECL goes out of
|
||||
scope, the CLEANUP_EXPR must be run. */
|
||||
DEFTREECODE (CLEANUP_STMT, "cleanup_stmt", 'e', 2)
|
||||
/* CTOR_INITIALIZER is a placeholder in template code for a call to
|
||||
setup_vtbl_pointer (and appears in all functions, not just ctors). */
|
||||
DEFTREECODE (CTOR_INITIALIZER, "ctor_initializer", 'e', 2)
|
||||
|
|
|
@ -322,8 +322,6 @@ typedef struct ptrmem_cst
|
|||
set_namespace_binding ((NODE), current_namespace, (VAL))
|
||||
|
||||
#define CLEANUP_P(NODE) TREE_LANG_FLAG_0 (TRY_BLOCK_CHECK (NODE))
|
||||
#define CLEANUP_DECL(NODE) TREE_OPERAND (CLEANUP_STMT_CHECK (NODE), 0)
|
||||
#define CLEANUP_EXPR(NODE) TREE_OPERAND (CLEANUP_STMT_CHECK (NODE), 1)
|
||||
|
||||
/* Returns nonzero iff TYPE1 and TYPE2 are the same type, in the usual
|
||||
sense of `same'. */
|
||||
|
|
|
@ -8035,8 +8035,7 @@ destroy_local_var (decl)
|
|||
cleanup = maybe_build_cleanup (decl);
|
||||
|
||||
/* Record the cleanup required for this declaration. */
|
||||
if (DECL_SIZE (decl) && TREE_TYPE (decl) != error_mark_node
|
||||
&& cleanup)
|
||||
if (DECL_SIZE (decl) && cleanup)
|
||||
finish_decl_cleanup (decl, cleanup);
|
||||
}
|
||||
|
||||
|
@ -14512,7 +14511,7 @@ maybe_build_cleanup (decl)
|
|||
|
||||
return rval;
|
||||
}
|
||||
return 0;
|
||||
return NULL_TREE;
|
||||
}
|
||||
|
||||
/* When a stmt has been parsed, this function is called. */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Tree-dumping functionality for intermediate representation.
|
||||
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
||||
Written by Mark Mitchell <mark@codesourcery.com>
|
||||
|
||||
This file is part of GNU CC.
|
||||
|
@ -390,13 +390,6 @@ cp_dump_tree (dump_info, t)
|
|||
dump_child ("decl", TREE_OPERAND (t, 2));
|
||||
break;
|
||||
|
||||
case CLEANUP_STMT:
|
||||
dump_stmt (di, t);
|
||||
dump_child ("decl", CLEANUP_DECL (t));
|
||||
dump_child ("expr", CLEANUP_EXPR (t));
|
||||
dump_next_stmt (di, t);
|
||||
break;
|
||||
|
||||
case CTOR_STMT:
|
||||
dump_stmt (di, t);
|
||||
if (CTOR_BEGIN_P (t))
|
||||
|
|
|
@ -2125,10 +2125,6 @@ cp_expand_stmt (t)
|
|||
{
|
||||
switch (TREE_CODE (t))
|
||||
{
|
||||
case CLEANUP_STMT:
|
||||
genrtl_decl_cleanup (CLEANUP_DECL (t), CLEANUP_EXPR (t));
|
||||
break;
|
||||
|
||||
case CTOR_STMT:
|
||||
genrtl_ctor_stmt (t);
|
||||
break;
|
||||
|
|
|
@ -1031,7 +1031,6 @@ cp_statement_code_p (code)
|
|||
switch (code)
|
||||
{
|
||||
case SUBOBJECT:
|
||||
case CLEANUP_STMT:
|
||||
case CTOR_STMT:
|
||||
case CTOR_INITIALIZER:
|
||||
case RETURN_INIT:
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
2002-03-15 Mark Mitchell <mark@codesourcery.com>
|
||||
|
||||
* g++.dg/opt/dtor1.C: New test.
|
||||
|
||||
2002-03-15 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
* gcc.c-torture/compile/20020315-1.c: New test.
|
||||
|
|
27
gcc/testsuite/g++.dg/opt/dtor1.C
Normal file
27
gcc/testsuite/g++.dg/opt/dtor1.C
Normal file
|
@ -0,0 +1,27 @@
|
|||
// { dg-do run }
|
||||
// { dg-options "-O2" }
|
||||
|
||||
int i;
|
||||
|
||||
struct S {
|
||||
S ();
|
||||
S (const S&);
|
||||
~S ();
|
||||
};
|
||||
|
||||
S::S () { ++i; }
|
||||
S::S (const S&) { ++i; }
|
||||
S::~S () { --i; }
|
||||
|
||||
inline void f (S) {
|
||||
}
|
||||
|
||||
int main () {
|
||||
{
|
||||
S s;
|
||||
f (s);
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
|
@ -548,6 +548,13 @@ dequeue_and_dump (di)
|
|||
dump_next_stmt (di, t);
|
||||
break;
|
||||
|
||||
case CLEANUP_STMT:
|
||||
dump_stmt (di, t);
|
||||
dump_child ("decl", CLEANUP_DECL (t));
|
||||
dump_child ("expr", CLEANUP_EXPR (t));
|
||||
dump_next_stmt (di, t);
|
||||
break;
|
||||
|
||||
case COMPOUND_STMT:
|
||||
dump_stmt (di, t);
|
||||
dump_child ("body", COMPOUND_BODY (t));
|
||||
|
|
|
@ -480,6 +480,7 @@ initialize_inlined_parameters (id, args, fn)
|
|||
tree init_stmt;
|
||||
tree var;
|
||||
tree value;
|
||||
tree cleanup;
|
||||
|
||||
/* Find the initializer. */
|
||||
value = a ? TREE_VALUE (a) : NULL_TREE;
|
||||
|
@ -558,16 +559,26 @@ initialize_inlined_parameters (id, args, fn)
|
|||
TREE_CHAIN (init_stmt) = init_stmts;
|
||||
init_stmts = init_stmt;
|
||||
}
|
||||
|
||||
/* See if we need to clean up the declaration. */
|
||||
cleanup = maybe_build_cleanup (var);
|
||||
if (cleanup)
|
||||
{
|
||||
tree cleanup_stmt;
|
||||
/* Build the cleanup statement. */
|
||||
cleanup_stmt = build_stmt (CLEANUP_STMT, var, cleanup);
|
||||
/* Add it to the *front* of the list; the list will be
|
||||
reversed below. */
|
||||
TREE_CHAIN (cleanup_stmt) = init_stmts;
|
||||
init_stmts = cleanup_stmt;
|
||||
}
|
||||
}
|
||||
|
||||
/* Evaluate trailing arguments. */
|
||||
for (; a; a = TREE_CHAIN (a))
|
||||
{
|
||||
tree init_stmt;
|
||||
tree value;
|
||||
|
||||
/* Find the initializer. */
|
||||
value = a ? TREE_VALUE (a) : NULL_TREE;
|
||||
tree value = TREE_VALUE (a);
|
||||
|
||||
if (! value || ! TREE_SIDE_EFFECTS (value))
|
||||
continue;
|
||||
|
|
Loading…
Add table
Reference in a new issue