aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2025-02-03 10:35:33 -0500
committerJason Merrill <jason@redhat.com>2025-04-19 10:01:53 -0400
commit6beb0a14aacd84ec49646237fc0f69c6765f956e (patch)
treecee1de01cad1c92ea5998bfd27062688730889da /gcc
parent1dd769b3d0d9251649dcb645d7ed6c4ba2202306 (diff)
downloadgcc-6beb0a14aacd84ec49646237fc0f69c6765f956e.zip
gcc-6beb0a14aacd84ec49646237fc0f69c6765f956e.tar.gz
gcc-6beb0a14aacd84ec49646237fc0f69c6765f956e.tar.bz2
c++: minor EXPR_STMT cleanup
I think it was around PR118574 that I noticed a few cases where we were unnecessarily wrapping a statement tree in a further EXPR_STMT. Let's avoid that and also use finish_expr_stmt in a few places in the coroutines code that were building EXPR_STMT directly. gcc/cp/ChangeLog: * coroutines.cc (coro_build_expr_stmt) (coro_build_cvt_void_expr_stmt): Remove. (build_actor_fn): Use finish_expr_stmt. * semantics.cc (finish_expr_stmt): Avoid wrapping statement in EXPR_STMT. (finish_stmt_expr_expr): Add comment.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/coroutines.cc21
-rw-r--r--gcc/cp/semantics.cc8
2 files changed, 8 insertions, 21 deletions
diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index b92d09f..743da06 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -1852,21 +1852,6 @@ coro_build_frame_access_expr (tree coro_ref, tree member_id, bool preserve_ref,
return expr;
}
-/* Helpers to build EXPR_STMT and void-cast EXPR_STMT, common ops. */
-
-static tree
-coro_build_expr_stmt (tree expr, location_t loc)
-{
- return maybe_cleanup_point_expr_void (build_stmt (loc, EXPR_STMT, expr));
-}
-
-static tree
-coro_build_cvt_void_expr_stmt (tree expr, location_t loc)
-{
- tree t = build1 (CONVERT_EXPR, void_type_node, expr);
- return coro_build_expr_stmt (t, loc);
-}
-
/* Helpers to build an artificial var, with location LOC, NAME and TYPE, in
CTX, and with initializer INIT. */
@@ -2582,8 +2567,7 @@ build_actor_fn (location_t loc, tree coro_frame_type, tree actor, tree fnbody,
tree hfa = build_new_method_call (ash, hfa_m, &args, NULL_TREE, LOOKUP_NORMAL,
NULL, tf_warning_or_error);
r = cp_build_init_expr (ash, hfa);
- r = coro_build_cvt_void_expr_stmt (r, loc);
- add_stmt (r);
+ finish_expr_stmt (r);
release_tree_vector (args);
/* Now we know the real promise, and enough about the frame layout to
@@ -2678,8 +2662,7 @@ build_actor_fn (location_t loc, tree coro_frame_type, tree actor, tree fnbody,
we must tail call them. However, some targets do not support indirect
tail calls to arbitrary callees. See PR94359. */
CALL_EXPR_TAILCALL (resume) = true;
- resume = coro_build_cvt_void_expr_stmt (resume, loc);
- add_stmt (resume);
+ finish_expr_stmt (resume);
r = build_stmt (loc, RETURN_EXPR, NULL);
gcc_checking_assert (maybe_cleanup_point_expr_void (r) == r);
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 7f23efd..1aa35d3 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -1180,10 +1180,13 @@ finish_expr_stmt (tree expr)
expr = error_mark_node;
/* Simplification of inner statement expressions, compound exprs,
- etc can result in us already having an EXPR_STMT. */
+ etc can result in us already having an EXPR_STMT or other statement
+ tree. Don't wrap them in EXPR_STMT. */
if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
{
- if (TREE_CODE (expr) != EXPR_STMT)
+ if (TREE_CODE (expr) != EXPR_STMT
+ && !STATEMENT_CLASS_P (expr)
+ && TREE_CODE (expr) != STATEMENT_LIST)
expr = build_stmt (loc, EXPR_STMT, expr);
expr = maybe_cleanup_point_expr_void (expr);
}
@@ -3082,6 +3085,7 @@ finish_stmt_expr_expr (tree expr, tree stmt_expr)
}
else if (processing_template_decl)
{
+ /* Not finish_expr_stmt because we don't want convert_to_void. */
expr = build_stmt (input_location, EXPR_STMT, expr);
expr = add_stmt (expr);
/* Mark the last statement so that we can recognize it as such at