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

Commit 48b809b

Browse files
committed
Remove stabilize in component_ref, add case for modify expressions.
1 parent 98c0826 commit 48b809b

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

gcc/d/d-codegen.cc

+22-10
Original file line numberDiff line numberDiff line change
@@ -524,14 +524,30 @@ d_save_expr (tree exp)
524524
static tree
525525
build_unary_op (tree_code code, tree type, tree arg)
526526
{
527-
/* Given ((e1, ...), eN):
528-
Treat the last RHS 'eN' expression as the lvalue part. */
527+
/* Given ((e1, ...), eN), treat the last RHS 'eN' expression as the
528+
lvalue part. */
529529
if (TREE_CODE (arg) == COMPOUND_EXPR)
530530
{
531531
tree result = build_unary_op (code, type, TREE_OPERAND (arg, 1));
532532
return compound_expr (TREE_OPERAND (arg, 0), result);
533533
}
534534

535+
/* Given (e1 = e2), (++e1), or (--e1), convert 'e1' into an lvalue. */
536+
if (TREE_CODE (arg) == MODIFY_EXPR
537+
|| TREE_CODE (arg) == PREINCREMENT_EXPR
538+
|| TREE_CODE (arg) == PREDECREMENT_EXPR)
539+
{
540+
if (TREE_SIDE_EFFECTS (TREE_OPERAND (arg, 0)))
541+
{
542+
arg = build2 (TREE_CODE (arg), TREE_TYPE (arg),
543+
stabilize_reference (TREE_OPERAND (arg, 0)),
544+
TREE_OPERAND (arg, 1));
545+
gcc_unreachable ();
546+
}
547+
return build_unary_op (code, type,
548+
compound_expr (arg, TREE_OPERAND (arg, 0)));
549+
}
550+
535551
if (code == ADDR_EXPR)
536552
{
537553
/* Can't take the address of a manifest constant, get the real value of
@@ -567,7 +583,8 @@ stabilize_expr2 (tree *valuep)
567583
tree expr = *valuep;
568584

569585
/* No side effects or expression has no value. */
570-
if (!TREE_SIDE_EFFECTS (expr) || VOID_TYPE_P (TREE_TYPE (expr)))
586+
if (!TREE_SIDE_EFFECTS (expr) || TREE_CODE (expr) == SAVE_EXPR
587+
|| VOID_TYPE_P (TREE_TYPE (expr)))
571588
return NULL_TREE;
572589

573590
tree init = force_target_expr (expr);
@@ -1322,9 +1339,6 @@ component_ref (tree object, tree field)
13221339

13231340
gcc_assert (TREE_CODE (field) == FIELD_DECL);
13241341

1325-
/* Maybe rewrite: (e1, e2).field => (e1, e2.field) */
1326-
tree init = stabilize_expr (&object);
1327-
13281342
/* If the FIELD is from an anonymous aggregate, generate a reference
13291343
to the anonymous data member, and recur to find FIELD. */
13301344
if (ANON_AGGR_TYPE_P (DECL_CONTEXT (field)))
@@ -1334,10 +1348,8 @@ component_ref (tree object, tree field)
13341348
object = component_ref (object, anonymous_field);
13351349
}
13361350

1337-
tree result = fold_build3_loc (input_location, COMPONENT_REF,
1338-
TREE_TYPE (field), object, field, NULL_TREE);
1339-
1340-
return compound_expr (init, result);
1351+
return fold_build3_loc (input_location, COMPONENT_REF, TREE_TYPE (field),
1352+
object, field, NULL_TREE);
13411353
}
13421354

13431355
/* Build an assignment expression of lvalue LHS from value RHS.

0 commit comments

Comments
 (0)