From 9d85d30c20219b6ae3657c1ede69d7634aaad96f Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Tue, 14 Sep 1999 00:50:07 +0000 Subject: [PATCH] cp-tree.h (build_target_expr): New function. * cp-tree.h (build_target_expr): New function. * call.c (build_conditional_expr): Use build_target_expr. (convert_like): Likewise. (build_over_call): Likewise. * cvt.c (build_up_reference): Likewise. * decl.c (build_cleanup_on_safe_obstack): Fold into ... (destroy_local_var): Here. (build_target_expr): New function. * tree.c (build_cplus_new): Use it. (get_target_expr): Likewise. From-SVN: r29387 --- gcc/cp/ChangeLog | 13 ++++++++++ gcc/cp/call.c | 8 +++--- gcc/cp/cp-tree.h | 1 + gcc/cp/cvt.c | 2 +- gcc/cp/decl.c | 74 ++++++++++++++++++++++++-------------------------------- gcc/cp/tree.c | 5 ++-- 6 files changed, 51 insertions(+), 52 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3b4e638..4a33e63 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,16 @@ +1999-09-13 Mark Mitchell + + * cp-tree.h (build_target_expr): New function. + * call.c (build_conditional_expr): Use build_target_expr. + (convert_like): Likewise. + (build_over_call): Likewise. + * cvt.c (build_up_reference): Likewise. + * decl.c (build_cleanup_on_safe_obstack): Fold into ... + (destroy_local_var): Here. + (build_target_expr): New function. + * tree.c (build_cplus_new): Use it. + (get_target_expr): Likewise. + 1999-09-13 Nathan Sidwell * typeck.c (expr_sizeof): Don't decay arrays and functions. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index bfc430d..bce1741 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -3080,8 +3080,7 @@ build_conditional_expr (arg1, arg2, arg3) { tree slot = build (VAR_DECL, result_type); layout_decl (slot, 0); - result = build (TARGET_EXPR, result_type, - slot, result, NULL_TREE, NULL_TREE); + result = build_target_expr (slot, result); } /* If this expression is an rvalue, but might be mistaken for an @@ -3749,8 +3748,7 @@ convert_like (convs, expr) tree type = TREE_TYPE (TREE_OPERAND (convs, 0)); tree slot = build_decl (VAR_DECL, NULL_TREE, type); DECL_ARTIFICIAL (slot) = 1; - expr = build (TARGET_EXPR, type, slot, expr, - NULL_TREE, NULL_TREE); + expr = build_target_expr (slot, expr); TREE_SIDE_EFFECTS (expr) = 1; } @@ -4039,7 +4037,7 @@ build_over_call (cand, args, flags) else if (TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn))) { val = build_decl (VAR_DECL, NULL_TREE, DECL_CONTEXT (fn)); - val = build (TARGET_EXPR, DECL_CONTEXT (fn), val, arg, 0, 0); + val = build_target_expr (val, arg); TREE_SIDE_EFFECTS (val) = 1; return val; } diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 2cb0574..8c587cb 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -3247,6 +3247,7 @@ extern tree cp_namespace_decls PROTO((tree)); extern tree create_implicit_typedef PROTO((tree, tree)); extern tree maybe_push_decl PROTO((tree)); extern void emit_local_var PROTO((tree)); +extern tree build_target_expr PROTO((tree, tree)); /* in decl2.c */ extern void init_decl2 PROTO((void)); diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index 93d8a43..d1bdb2e 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -364,7 +364,7 @@ build_up_reference (type, arg, flags) { tree slot = build_decl (VAR_DECL, NULL_TREE, argtype); DECL_ARTIFICIAL (slot) = 1; - arg = build (TARGET_EXPR, argtype, slot, arg, NULL_TREE, NULL_TREE); + arg = build_target_expr (slot, arg); TREE_SIDE_EFFECTS (arg) = 1; } diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 08bf7eb..af4bf13 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -169,7 +169,6 @@ static void pop_labels PROTO((tree)); static void maybe_deduce_size_from_array_init PROTO((tree, tree)); static tree layout_var_decl PROTO((tree, tree)); static void maybe_commonize_var PROTO((tree)); -static tree build_cleanup_on_safe_obstack PROTO((tree)); static tree check_initializer PROTO((tree, tree)); static void make_rtl_for_nonlocal_decl PROTO((tree, tree, const char *)); static void push_cp_function_context PROTO((struct function *)); @@ -7121,47 +7120,6 @@ layout_var_decl (decl, init) return init; } -/* Return a cleanup for DECL, created on whatever obstack is - appropriate. */ - -static tree -build_cleanup_on_safe_obstack (decl) - tree decl; -{ - tree cleanup; - tree type; - int need_pop; - - type = TREE_TYPE (decl); - - /* Only variables get cleaned up. */ - if (TREE_CODE (decl) != VAR_DECL) - return NULL_TREE; - - /* And only things with destructors need cleaning up. */ - if (!TYPE_NEEDS_DESTRUCTOR (type)) - return NULL_TREE; - - if (TREE_CODE (decl) == VAR_DECL && - (DECL_EXTERNAL (decl) || TREE_STATIC (decl))) - /* We don't clean up things that aren't defined in this - translation unit, or that need a static cleanup. The latter - are handled by finish_file. */ - return NULL_TREE; - - /* Switch to an obstack that will live until the point where the - cleanup code is actually expanded. */ - need_pop = suspend_momentary (); - - /* Compute the cleanup. */ - cleanup = maybe_build_cleanup (decl); - - /* Pop back to the obstack we were on before. */ - resume_momentary (need_pop); - - return cleanup; -} - /* If a local static variable is declared in an inline function, or if we have a weak definition, we must endeavor to create only one instance of the variable at link-time. */ @@ -7557,7 +7515,26 @@ void destroy_local_var (decl) tree decl; { - tree cleanup = build_cleanup_on_safe_obstack (decl); + tree type = TREE_TYPE (decl); + tree cleanup; + + /* Only variables get cleaned up. */ + if (TREE_CODE (decl) != VAR_DECL) + return; + + /* And only things with destructors need cleaning up. */ + if (!TYPE_NEEDS_DESTRUCTOR (type)) + return; + + if (TREE_CODE (decl) == VAR_DECL && + (DECL_EXTERNAL (decl) || TREE_STATIC (decl))) + /* We don't clean up things that aren't defined in this + translation unit, or that need a static cleanup. The latter + are handled by finish_file. */ + return; + + /* Compute the cleanup. */ + cleanup = maybe_build_cleanup (decl); /* Record the cleanup required for this declaration. */ if (DECL_SIZE (decl) && TREE_TYPE (decl) != error_mark_node @@ -14143,6 +14120,17 @@ maybe_build_cleanup_1 (decl, auto_delete) return 0; } +/* Build a TARGET_EXPR, initializing the DECL with the VALUE. */ + +tree +build_target_expr (decl, value) + tree decl; + tree value; +{ + return build (TARGET_EXPR, TREE_TYPE (decl), decl, value, + maybe_build_cleanup (decl), NULL_TREE); +} + /* If DECL is of a type which needs a cleanup, build that cleanup here. The cleanup does free the storage with a call to delete. */ diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index d9db3b0..f0f0141 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -251,7 +251,7 @@ build_cplus_new (type, init) = (TREE_CODE (fn) == ADDR_EXPR && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0))); - rval = build (TARGET_EXPR, type, slot, rval, NULL_TREE, NULL_TREE); + rval = build_target_expr (slot, rval); TREE_SIDE_EFFECTS (rval) = 1; return rval; @@ -269,8 +269,7 @@ get_target_expr (init) slot = build (VAR_DECL, TREE_TYPE (init)); DECL_ARTIFICIAL (slot) = 1; layout_decl (slot, 0); - rval = build (TARGET_EXPR, TREE_TYPE (init), slot, init, - NULL_TREE, NULL_TREE); + rval = build_target_expr (slot, init); TREE_SIDE_EFFECTS (rval) = 1; return rval; -- 2.7.4