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

Commit 146f21d

Browse files
committed
Add build_unary_op, use it instead of stabilize_expr for unary NOP
1 parent 7485d25 commit 146f21d

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

gcc/d/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2018-05-01 Iain Buclaw <[email protected]>
2+
3+
* d-codegen.cc (build_unary_op): New function.
4+
(build_nop): Use build_unary_op.
5+
16
2018-04-02 Iain Buclaw <[email protected]>
27

38
* d-lang.cc (doing_semantic_analysis_p): New variable.

gcc/d/d-codegen.cc

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,24 @@ d_save_expr (tree exp)
517517
return exp;
518518
}
519519

520+
/* Build an unary op CODE to the expression ARG. If the expression can be
521+
broken down so that the operation is applied only to the part whose value we
522+
care about, then handle lowering to keep lvalues trivial. */
523+
524+
static tree
525+
build_unary_op (tree_code code, tree type, tree arg)
526+
{
527+
/* Given ((e1, ...), eN):
528+
Handle the last RHS 'eN' expression as an lvalue. */
529+
if (TREE_CODE (arg) == COMPOUND_EXPR)
530+
{
531+
tree result = build_unary_op (code, type, TREE_OPERAND (arg, 1));
532+
return compound_expr (TREE_OPERAND (arg, 0), result);
533+
}
534+
535+
return fold_build1_loc (input_location, code, type, arg);
536+
}
537+
520538
/* VALUEP is an expression we want to pre-evaluate or perform a computation on.
521539
The expression returned by this function is the part whose value we don't
522540
care about, storing the value in VALUEP. Callers must ensure that the
@@ -1360,11 +1378,7 @@ build_nop (tree type, tree exp)
13601378
if (error_operand_p (exp))
13611379
return exp;
13621380

1363-
/* Maybe rewrite: cast(TYPE)(e1, e2) => (e1, cast(TYPE) e2) */
1364-
tree init = stabilize_expr (&exp);
1365-
exp = fold_build1_loc (input_location, NOP_EXPR, type, exp);
1366-
1367-
return compound_expr (init, exp);
1381+
return build_unary_op (NOP_EXPR, type, exp);
13681382
}
13691383

13701384
/* Return EXP to be viewed as being another type TYPE. Same as build_nop,

0 commit comments

Comments
 (0)