From f1f88294790f26d88bce7667a99513f50248030b Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Wed, 2 May 2018 15:34:33 +0200 Subject: [PATCH] Use target_expr based stabilize in indirect_ref --- gcc/d/d-codegen.cc | 16 ++++++++++++++-- gcc/d/d-tree.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc index 2066f7db6..36db04d59 100644 --- a/gcc/d/d-codegen.cc +++ b/gcc/d/d-codegen.cc @@ -561,6 +561,17 @@ build_unary_op (tree_code code, tree type, tree arg) care about, storing the value in VALUEP. Callers must ensure that the returned expression is evaluated before VALUEP. */ +tree +stabilize_expr2 (tree exp) +{ + if (!TREE_SIDE_EFFECTS (exp) || VOID_TYPE_P (TREE_TYPE (exp))) + return exp; + + tree init = force_target_expr (exp); + + return compound_expr (init, TARGET_EXPR_SLOT (init)); +} + tree stabilize_expr (tree *valuep) { @@ -1193,6 +1204,7 @@ find_aggregate_field (tree type, tree ident, tree offset) return NULL_TREE; } + /* Return a constructor that matches the layout of the class expression EXP. */ tree @@ -1530,7 +1542,7 @@ indirect_ref (tree type, tree exp) return exp; /* Maybe rewrite: *(e1, e2) => (e1, *e2) */ - tree init = stabilize_expr (&exp); + exp = stabilize_expr2 (exp); if (TREE_CODE (TREE_TYPE (exp)) == REFERENCE_TYPE) exp = fold_build1 (INDIRECT_REF, type, exp); @@ -1540,7 +1552,7 @@ indirect_ref (tree type, tree exp) exp = build_deref (exp); } - return compound_expr (init, exp); + return exp; } /* Returns indirect reference of EXP, which must be a pointer type. */ diff --git a/gcc/d/d-tree.h b/gcc/d/d-tree.h index 06a7190cf..77927245e 100644 --- a/gcc/d/d-tree.h +++ b/gcc/d/d-tree.h @@ -508,6 +508,7 @@ extern void extract_from_method_call (tree, tree &, tree &); extern tree build_vindex_ref (tree, tree, size_t); extern tree d_save_expr (tree); extern tree stabilize_expr (tree *); +extern tree stabilize_expr2 (tree); extern tree build_target_expr (tree, tree); extern tree force_target_expr (tree); extern tree build_address (tree);