c-common.c (statement_code_p): Handle CLEANUP_STMT.
authorMark Mitchell <mark@codesourcery.com>
Fri, 15 Mar 2002 20:08:39 +0000 (20:08 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Fri, 15 Mar 2002 20:08:39 +0000 (20:08 +0000)
* 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

16 files changed:
gcc/ChangeLog
gcc/c-common.c
gcc/c-common.def
gcc/c-common.h
gcc/c-semantics.c
gcc/cp/ChangeLog
gcc/cp/cp-tree.def
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/dump.c
gcc/cp/semantics.c
gcc/cp/tree.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/dtor1.C [new file with mode: 0644]
gcc/tree-dump.c
gcc/tree-inline.c

index b6e1d87aa401e00a4121ca7419fd25b850068070..2f3e025caf7b60593aa4eeaa78209226da2c187b 100644 (file)
@@ -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
index 0352eb6bbc985d5dcf27586c7e04a00e89f75080..4b2350e8cc42e1ea006a8f9646bb13266d74a8d8 100644 (file)
@@ -3213,6 +3213,7 @@ statement_code_p (code)
 {
   switch (code)
     {
+    case CLEANUP_STMT:
     case EXPR_STMT:
     case COMPOUND_STMT:
     case DECL_STMT:
index 293f4b21bd32b606caebc312cd70e969fd77fa67..7ad9e385229a93c37a1705b4bf8b41f7104c74e4 100644 (file)
@@ -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
index 314a6ba3a15d4b1e305b0d227477a01c1a3d08a0..280c5b0d2d2ac86368de2cfee5bedab311c82323 100644 (file)
@@ -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))
index 8f99bc1f64c679f26aee024e647fe56a2372a298..3d8759d8584cdf4237a6d297bae0b3300b9a53ed 100644 (file)
@@ -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);
index 111edcc283a2adbfa73626f7709980c08a45bf40..90ac3c60d8eb484148b757644d8c80b2711baa2a 100644 (file)
@@ -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
index dbe990a2e11c3ab96755cb26dd030f02bf75c72c..3854525611413c4764ab482bdbc65f2a732027fc 100644 (file)
@@ -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)
index 5f58ef66ca5f2b6fd05fa1baef874359c323ce50..68a141c5b5673a4578c8073080a98f86bc4b3b1b 100644 (file)
@@ -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'.  */
index d76c6a5c49041bf106cabeaad5d42fdc68b21c51..30351c90d44c581b1b1a1fcd68b347076f52b63b 100644 (file)
@@ -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;
 }
 \f
 /* When a stmt has been parsed, this function is called.  */
index 98c1fc49d87b0ad5ee0d88e45cef9d257feb75e0..6dd60baf73be26581b34c727ff32677a2a5c042d 100644 (file)
@@ -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))
index 3ec15a9bb910352ac04e209d385c0729e7614d75..14ecf05f9b5c14d36348b0f55b4702f85696ccfd 100644 (file)
@@ -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;
index 5a8b902455bff178992207d4ae1788d606fc8094..acd6fbf3f1db3ef407445d7da968baf80262d8e5 100644 (file)
@@ -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:
index b60f1145901315435d2cd7e12f638b8767f7b263..531289ff99e3b37d9c30f1d757fbfd97fe0f00d3 100644 (file)
@@ -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.
diff --git a/gcc/testsuite/g++.dg/opt/dtor1.C b/gcc/testsuite/g++.dg/opt/dtor1.C
new file mode 100644 (file)
index 0000000..0352676
--- /dev/null
@@ -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;
+}
+
index 9eac6e075f104610203ddcf9750408f22d336111..d8d8e23ea5f1fc3921348d1a14ff87a221bf79fe 100644 (file)
@@ -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));
index f8ca55c780f0514b3e7f4992fa4a69818ee3fe91..ce548849d2d14bb2b37f526e371f1bab6885748f 100644 (file)
@@ -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;