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

Commit b81d3f8

Browse files
committed
Use build_unary_op instead of stabilize_expr for ADDR_EXPR
1 parent ac94796 commit b81d3f8

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

gcc/d/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* d-codegen.cc (build_unary_op): New function.
44
(build_nop): Use build_unary_op.
5+
(build_address): Move expression handling to build_unary_op.
56

67
2018-04-02 Iain Buclaw <[email protected]>
78

gcc/d/d-codegen.cc

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,27 @@ build_unary_op (tree_code code, tree type, tree arg)
532532
return compound_expr (TREE_OPERAND (arg, 0), result);
533533
}
534534

535+
if (code == ADDR_EXPR)
536+
{
537+
/* Can't take the address of a manifest constant, get the real value of
538+
the decl instead. */
539+
if (TREE_CODE (arg) == CONST_DECL)
540+
arg = DECL_INITIAL (arg);
541+
542+
/* Some expression lowering may request an address of a compile-time
543+
constant. Make sure it is assigned to a location we can reference. */
544+
if (CONSTANT_CLASS_P (arg) && TREE_CODE (arg) != STRING_CST)
545+
arg = force_target_expr (arg);
546+
547+
d_mark_addressable (arg);
548+
tree result = build_fold_addr_expr_with_type_loc (input_location, arg,
549+
type);
550+
if (TREE_CODE (result) == ADDR_EXPR)
551+
TREE_NO_TRAMPOLINE (result) = 1;
552+
553+
return result;
554+
}
555+
535556
return fold_build1_loc (input_location, code, type, arg);
536557
}
537558

@@ -624,25 +645,7 @@ build_address (tree exp)
624645
else
625646
ptrtype = build_pointer_type (type);
626647

627-
/* Maybe rewrite: &(e1, e2) => (e1, &e2). */
628-
tree init = stabilize_expr (&exp);
629-
630-
/* Can't take the address of a manifest constant, instead use its value. */
631-
if (TREE_CODE (exp) == CONST_DECL)
632-
exp = DECL_INITIAL (exp);
633-
634-
/* Some expression lowering may request an address of a compile-time constant.
635-
Make sure it is assigned to a location we can reference. */
636-
if (CONSTANT_CLASS_P (exp) && TREE_CODE (exp) != STRING_CST)
637-
exp = force_target_expr (exp);
638-
639-
d_mark_addressable (exp);
640-
exp = build_fold_addr_expr_with_type_loc (input_location, exp, ptrtype);
641-
642-
if (TREE_CODE (exp) == ADDR_EXPR)
643-
TREE_NO_TRAMPOLINE (exp) = 1;
644-
645-
return compound_expr (init, exp);
648+
return build_unary_op (ADDR_EXPR, ptrtype, exp);
646649
}
647650

648651
/* Mark EXP saying that we need to be able to take the

0 commit comments

Comments
 (0)