aboutsummaryrefslogtreecommitdiff
path: root/gcc/d/expr.cc
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2023-10-28 09:42:15 +0200
committerIain Buclaw <ibuclaw@gdcproject.org>2023-10-28 09:53:36 +0200
commit5d2a360f0a541646abb11efdbabc33c6a04de7ee (patch)
tree30f899e4220039d70a9c244498b54dbc0cee7931 /gcc/d/expr.cc
parent7f974c5fd4f59a9d8dd20c49a0e2909cb290f4b4 (diff)
downloadgcc-5d2a360f0a541646abb11efdbabc33c6a04de7ee.zip
gcc-5d2a360f0a541646abb11efdbabc33c6a04de7ee.tar.gz
gcc-5d2a360f0a541646abb11efdbabc33c6a04de7ee.tar.bz2
d: Add warning for call expression without side effects
In the last merge of the dmd front-end with upstream (r14-4830), this warning got removed from the semantic passes. Reimplement the warning for the code generation pass instead, where it cannot have an effect on conditional compilation. gcc/d/ChangeLog: * d-codegen.cc (call_side_effect_free_p): New function. * d-tree.h (CALL_EXPR_WARN_IF_UNUSED): New macro. (call_side_effect_free_p): New prototype. * expr.cc (ExprVisitor::visit (CallExp *)): Set CALL_EXPR_WARN_IF_UNUSED on matched call expressions. (ExprVisitor::visit (NewExp *)): Don't dereference the result of an allocation call here. * toir.cc (add_stmt): Emit warning when call expression added to statement list without being used. gcc/testsuite/ChangeLog: * gdc.dg/Wunused_value.d: New test.
Diffstat (limited to 'gcc/d/expr.cc')
-rw-r--r--gcc/d/expr.cc13
1 files changed, 12 insertions, 1 deletions
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 52243e6..72180b1 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -1714,6 +1714,12 @@ public:
build the call expression. */
tree exp = d_build_call (tf, callee, object, e->arguments);
+ /* Record whether the call expression has no side effects, so we can check
+ for an unused return value later. */
+ if (TREE_CODE (exp) == CALL_EXPR && CALL_EXPR_FN (exp) != NULL_TREE
+ && call_side_effect_free_p (e->f, e->e1->type))
+ CALL_EXPR_WARN_IF_UNUSED (exp) = 1;
+
if (returnvalue != NULL_TREE)
exp = compound_expr (exp, returnvalue);
@@ -2338,7 +2344,12 @@ public:
new_call = d_save_expr (new_call);
se->type = sd->type;
se->sym = new_call;
- result = compound_expr (build_expr (se), new_call);
+
+ /* Setting `se->sym' would mean that the result of the
+ constructed struct literal expression is `*(new_call)'.
+ Strip off the indirect reference, as we don't mean to
+ compute the value yet. */
+ result = build_address (build_expr (se));
}
else
result = new_call;