Skip to content
This repository has been archived by the owner on Jun 20, 2019. It is now read-only.

Commit

Permalink
Use target_expr based stabilize in indirect_ref
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuclaw committed May 2, 2018
1 parent b81d3f8 commit f1f8829
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions gcc/d/d-codegen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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. */
Expand Down
1 change: 1 addition & 0 deletions gcc/d/d-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f1f8829

Please sign in to comment.