diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2023-10-28 09:42:15 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2023-10-28 09:53:36 +0200 |
commit | 5d2a360f0a541646abb11efdbabc33c6a04de7ee (patch) | |
tree | 30f899e4220039d70a9c244498b54dbc0cee7931 /gcc/d/d-tree.h | |
parent | 7f974c5fd4f59a9d8dd20c49a0e2909cb290f4b4 (diff) | |
download | gcc-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/d-tree.h')
-rw-r--r-- | gcc/d/d-tree.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/gcc/d/d-tree.h b/gcc/d/d-tree.h index 66c2f24..ed26533 100644 --- a/gcc/d/d-tree.h +++ b/gcc/d/d-tree.h @@ -47,6 +47,7 @@ typedef Array <Expression *> Expressions; /* Usage of TREE_LANG_FLAG_?: 0: METHOD_CALL_EXPR + 1: CALL_EXPR_WARN_IF_UNUSED (in CALL_EXPR). Usage of TYPE_LANG_FLAG_?: 0: TYPE_SHARED @@ -357,6 +358,11 @@ lang_tree_node #define METHOD_CALL_EXPR(NODE) \ (TREE_LANG_FLAG_0 (NODE)) +/* True if the CALL_EXPR is free of side effects, and its return value + should not be discarded. */ +#define CALL_EXPR_WARN_IF_UNUSED(NODE) \ + (TREE_LANG_FLAG_1 (CALL_EXPR_CHECK (NODE))) + /* True if the type was declared 'shared'. */ #define TYPE_SHARED(NODE) \ (TYPE_LANG_FLAG_0 (NODE)) @@ -594,6 +600,7 @@ extern tree build_bounds_slice_condition (SliceExp *, tree, tree, tree); extern bool array_bounds_check (void); extern bool checkaction_trap_p (void); extern TypeFunction *get_function_type (Type *); +extern bool call_side_effect_free_p (FuncDeclaration *, Type *); extern bool call_by_alias_p (FuncDeclaration *, FuncDeclaration *); extern tree d_build_call_expr (FuncDeclaration *, tree, Expressions *); extern tree d_build_call (TypeFunction *, tree, tree, Expressions *); |