From: Jason Merrill <jason@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>, Alexander Monakov <amonakov@ispras.ru>
Cc: Marek Polacek <polacek@redhat.com>,
Richard Biener <rguenther@suse.de>,
Nathaniel Shead <nathanieloshead@gmail.com>,
gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++: End lifetime of objects in constexpr after destructor call [PR71093]
Date: Tue, 12 Dec 2023 10:24:53 -0500 [thread overview]
Message-ID: <9f1eaeb5-7de7-42c8-ae2a-dc74e6db99f2@redhat.com> (raw)
In-Reply-To: <ZXhA5VTvBIFZtU1q@tucnak>
[-- Attachment #1: Type: text/plain, Size: 1061 bytes --]
On 12/12/23 06:15, Jakub Jelinek wrote:
> On Tue, Dec 12, 2023 at 02:13:43PM +0300, Alexander Monakov wrote:
>>
>>
>> On Tue, 12 Dec 2023, Jakub Jelinek wrote:
>>
>>> On Mon, Dec 11, 2023 at 05:00:50PM -0500, Jason Merrill wrote:
>>>> In discussion of PR71093 it came up that more clobber_kind options would be
>>>> useful within the C++ front-end.
>>>>
>>>> gcc/ChangeLog:
>>>>
>>>> * tree-core.h (enum clobber_kind): Rename CLOBBER_EOL to
>>>> CLOBBER_STORAGE_END. Add CLOBBER_STORAGE_BEGIN,
>>>> CLOBBER_OBJECT_BEGIN, CLOBBER_OBJECT_END.
>>>> * gimple-lower-bitint.cc
>>>> * gimple-ssa-warn-access.cc
>>>> * gimplify.cc
>>>> * tree-inline.cc
>>>> * tree-ssa-ccp.cc: Adjust for rename.
>>
>> Doesn't build_clobber_this in the C++ front-end need to be adjusted too?
>> I think it is used to place clobbers at start of the ctor (should be
>> CLOBBER_OBJECT_BEGIN in the new nomenclature) and end of the dtor (i.e.
>> CLOBBER_OBJECT_END).
>
> You're right.
I had been thinking to leave that to Nathaniel's patch, but sure, I'll
hoist those bits out:
[-- Attachment #2: 0001-tree-add-to-clobber_kind.patch --]
[-- Type: text/x-patch, Size: 12198 bytes --]
From 29b54f1e2a832f74bdbdba738991d3330b0b4577 Mon Sep 17 00:00:00 2001
From: Jason Merrill <jason@redhat.com>
Date: Mon, 11 Dec 2023 11:35:31 -0500
Subject: [PATCH] tree: add to clobber_kind
To: gcc-patches@gcc.gnu.org
In discussion of PR71093 it came up that more clobber_kind options would be
useful within the C++ front-end.
gcc/ChangeLog:
* tree-core.h (enum clobber_kind): Rename CLOBBER_EOL to
CLOBBER_STORAGE_END. Add CLOBBER_STORAGE_BEGIN,
CLOBBER_OBJECT_BEGIN, CLOBBER_OBJECT_END.
* gimple-lower-bitint.cc
* gimple-ssa-warn-access.cc
* gimplify.cc
* tree-inline.cc
* tree-ssa-ccp.cc: Adjust for rename.
* tree-pretty-print.cc: And handle new values.
gcc/cp/ChangeLog:
* call.cc (build_trivial_dtor_call): Use CLOBBER_OBJECT_END.
* decl.cc (build_clobber_this): Take clobber_kind argument.
(start_preparsed_function): Pass CLOBBER_OBJECT_BEGIN.
(begin_destructor_body): Pass CLOBBER_OBJECT_END.
gcc/testsuite/ChangeLog:
* gcc.dg/pr87052.c: Adjust expected CLOBBER output.
Co-authored-by: Nathaniel Shead <nathanieloshead@gmail.com>
---
gcc/tree-core.h | 13 ++++++++++---
gcc/cp/call.cc | 2 +-
gcc/cp/decl.cc | 9 +++++----
gcc/gimple-lower-bitint.cc | 10 ++++++----
gcc/gimple-ssa-warn-access.cc | 2 +-
gcc/gimplify.cc | 9 +++++----
gcc/testsuite/gcc.dg/pr87052.c | 4 ++--
gcc/tree-inline.cc | 6 ++++--
gcc/tree-pretty-print.cc | 19 +++++++++++++++++--
gcc/tree-ssa-ccp.cc | 2 +-
10 files changed, 52 insertions(+), 24 deletions(-)
diff --git a/gcc/tree-core.h b/gcc/tree-core.h
index 04c04cf2f37..58aa598f3bb 100644
--- a/gcc/tree-core.h
+++ b/gcc/tree-core.h
@@ -986,12 +986,19 @@ enum annot_expr_kind {
annot_expr_kind_last
};
-/* The kind of a TREE_CLOBBER_P CONSTRUCTOR node. */
+/* The kind of a TREE_CLOBBER_P CONSTRUCTOR node. Other than _UNDEF, these are
+ in roughly sequential order. */
enum clobber_kind {
/* Unspecified, this clobber acts as a store of an undefined value. */
CLOBBER_UNDEF,
- /* This clobber ends the lifetime of the storage. */
- CLOBBER_EOL,
+ /* Beginning of storage duration, e.g. malloc. */
+ CLOBBER_STORAGE_BEGIN,
+ /* Beginning of object lifetime, e.g. C++ constructor. */
+ CLOBBER_OBJECT_BEGIN,
+ /* End of object lifetime, e.g. C++ destructor. */
+ CLOBBER_OBJECT_END,
+ /* End of storage duration, e.g. free. */
+ CLOBBER_STORAGE_END,
CLOBBER_LAST
};
diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 4f0abf8e93f..aaee34f35b0 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -9716,7 +9716,7 @@ build_trivial_dtor_call (tree instance, bool no_ptr_deref)
}
/* A trivial destructor should still clobber the object. */
- tree clobber = build_clobber (TREE_TYPE (instance));
+ tree clobber = build_clobber (TREE_TYPE (instance), CLOBBER_OBJECT_END);
return build2 (MODIFY_EXPR, void_type_node,
instance, clobber);
}
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index b1ada1d5215..4d17ead123a 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -17401,7 +17401,7 @@ implicit_default_ctor_p (tree fn)
storage is dead when we enter the constructor or leave the destructor. */
static tree
-build_clobber_this ()
+build_clobber_this (clobber_kind kind)
{
/* Clobbering an empty base is pointless, and harmful if its one byte
TYPE_SIZE overlays real data. */
@@ -17417,7 +17417,7 @@ build_clobber_this ()
if (!vbases)
ctype = CLASSTYPE_AS_BASE (ctype);
- tree clobber = build_clobber (ctype);
+ tree clobber = build_clobber (ctype, kind);
tree thisref = current_class_ref;
if (ctype != current_class_type)
@@ -17836,7 +17836,7 @@ start_preparsed_function (tree decl1, tree attrs, int flags)
because part of the initialization might happen before we enter the
constructor, via AGGR_INIT_ZERO_FIRST (c++/68006). */
&& !implicit_default_ctor_p (decl1))
- finish_expr_stmt (build_clobber_this ());
+ finish_expr_stmt (build_clobber_this (CLOBBER_OBJECT_BEGIN));
if (!processing_template_decl
&& DECL_CONSTRUCTOR_P (decl1)
@@ -18074,7 +18074,8 @@ begin_destructor_body (void)
finish_decl_cleanup (NULL_TREE, stmt);
}
else
- finish_decl_cleanup (NULL_TREE, build_clobber_this ());
+ finish_decl_cleanup (NULL_TREE,
+ build_clobber_this (CLOBBER_OBJECT_END));
}
/* And insert cleanups for our bases and members so that they
diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc
index c55c32fb40d..65a7bbe3fa9 100644
--- a/gcc/gimple-lower-bitint.cc
+++ b/gcc/gimple-lower-bitint.cc
@@ -806,7 +806,8 @@ bitint_large_huge::handle_operand (tree op, tree idx)
&& m_after_stmt
&& bitmap_bit_p (m_single_use_names, SSA_NAME_VERSION (op)))
{
- tree clobber = build_clobber (TREE_TYPE (m_vars[p]), CLOBBER_EOL);
+ tree clobber = build_clobber (TREE_TYPE (m_vars[p]),
+ CLOBBER_STORAGE_END);
g = gimple_build_assign (m_vars[p], clobber);
gimple_stmt_iterator gsi = gsi_for_stmt (m_after_stmt);
gsi_insert_after (&gsi, g, GSI_SAME_STMT);
@@ -2063,7 +2064,7 @@ bitint_large_huge::handle_operand_addr (tree op, gimple *stmt,
tree ret = build_fold_addr_expr (var);
if (!stmt_ends_bb_p (gsi_stmt (m_gsi)))
{
- tree clobber = build_clobber (atype, CLOBBER_EOL);
+ tree clobber = build_clobber (atype, CLOBBER_STORAGE_END);
g = gimple_build_assign (var, clobber);
gsi_insert_after (&m_gsi, g, GSI_SAME_STMT);
}
@@ -2100,7 +2101,8 @@ bitint_large_huge::handle_operand_addr (tree op, gimple *stmt,
ret = build_fold_addr_expr (var);
if (!stmt_ends_bb_p (gsi_stmt (m_gsi)))
{
- tree clobber = build_clobber (m_limb_type, CLOBBER_EOL);
+ tree clobber = build_clobber (m_limb_type,
+ CLOBBER_STORAGE_END);
g = gimple_build_assign (var, clobber);
gsi_insert_after (&m_gsi, g, GSI_SAME_STMT);
}
@@ -3707,7 +3709,7 @@ bitint_large_huge::finish_arith_overflow (tree var, tree obj, tree type,
}
if (var)
{
- tree clobber = build_clobber (TREE_TYPE (var), CLOBBER_EOL);
+ tree clobber = build_clobber (TREE_TYPE (var), CLOBBER_STORAGE_END);
g = gimple_build_assign (var, clobber);
gsi_insert_after (&m_gsi, g, GSI_SAME_STMT);
}
diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
index 1646bd1be14..f04c2530869 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -4364,7 +4364,7 @@ void
pass_waccess::check_stmt (gimple *stmt)
{
if (m_check_dangling_p
- && gimple_clobber_p (stmt, CLOBBER_EOL))
+ && gimple_clobber_p (stmt, CLOBBER_STORAGE_END))
{
/* Ignore clobber statements in blocks with exceptional edges. */
basic_block bb = gimple_bb (stmt);
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index 342e43a7f25..afeaea873c0 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -1518,7 +1518,7 @@ gimplify_bind_expr (tree *expr_p, gimple_seq *pre_p)
tmp = build_call_expr_loc (EXPR_LOCATION (*e), tmp, 2, v,
build_zero_cst (ptr_type_node));
tsi_link_after (&e, tmp, TSI_SAME_STMT);
- tmp = build_clobber (TREE_TYPE (v), CLOBBER_EOL);
+ tmp = build_clobber (TREE_TYPE (v), CLOBBER_STORAGE_END);
tmp = fold_build2_loc (loc, MODIFY_EXPR, TREE_TYPE (v), v,
fold_convert (TREE_TYPE (v), tmp));
++e;
@@ -1651,7 +1651,7 @@ gimplify_bind_expr (tree *expr_p, gimple_seq *pre_p)
build_zero_cst (ptr_type_node));
gimplify_and_add (tmp, &cleanup);
gimple *clobber_stmt;
- tmp = build_clobber (TREE_TYPE (v), CLOBBER_EOL);
+ tmp = build_clobber (TREE_TYPE (v), CLOBBER_STORAGE_END);
clobber_stmt = gimple_build_assign (v, tmp);
gimple_set_location (clobber_stmt, end_locus);
gimplify_seq_add_stmt (&cleanup, clobber_stmt);
@@ -1665,7 +1665,7 @@ gimplify_bind_expr (tree *expr_p, gimple_seq *pre_p)
&& !is_gimple_reg (t)
&& flag_stack_reuse != SR_NONE)
{
- tree clobber = build_clobber (TREE_TYPE (t), CLOBBER_EOL);
+ tree clobber = build_clobber (TREE_TYPE (t), CLOBBER_STORAGE_END);
gimple *clobber_stmt;
clobber_stmt = gimple_build_assign (t, clobber);
gimple_set_location (clobber_stmt, end_locus);
@@ -7417,7 +7417,8 @@ gimplify_target_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
{
if (flag_stack_reuse == SR_ALL)
{
- tree clobber = build_clobber (TREE_TYPE (temp), CLOBBER_EOL);
+ tree clobber = build_clobber (TREE_TYPE (temp),
+ CLOBBER_STORAGE_END);
clobber = build2 (MODIFY_EXPR, TREE_TYPE (temp), temp, clobber);
gimple_push_cleanup (temp, clobber, false, pre_p, true);
}
diff --git a/gcc/testsuite/gcc.dg/pr87052.c b/gcc/testsuite/gcc.dg/pr87052.c
index 796fe6440c1..90f3c3b14a8 100644
--- a/gcc/testsuite/gcc.dg/pr87052.c
+++ b/gcc/testsuite/gcc.dg/pr87052.c
@@ -36,6 +36,6 @@ void test (void)
{ dg-final { scan-tree-dump-times "b = \"a\\\\x00bc\";" 1 "gimple" } }
{ dg-final { scan-tree-dump-times "c = \"\";" 1 "gimple" } }
{ dg-final { scan-tree-dump-times "d = " 1 "gimple" } }
- { dg-final { scan-tree-dump-times "d = {CLOBBER\\(eol\\)}" 1 "gimple" } }
+ { dg-final { scan-tree-dump-times "d = {CLOBBER\\(eos\\)}" 1 "gimple" } }
{ dg-final { scan-tree-dump-times "e = " 1 "gimple" } }
- { dg-final { scan-tree-dump-times "e = {CLOBBER\\(eol\\)}" 1 "gimple" } } */
+ { dg-final { scan-tree-dump-times "e = {CLOBBER\\(eos\\)}" 1 "gimple" } } */
diff --git a/gcc/tree-inline.cc b/gcc/tree-inline.cc
index a4fc839a22d..137b83b7c83 100644
--- a/gcc/tree-inline.cc
+++ b/gcc/tree-inline.cc
@@ -5136,7 +5136,8 @@ expand_call_inline (basic_block bb, gimple *stmt, copy_body_data *id,
&& !is_gimple_reg (*varp)
&& !(id->debug_map && id->debug_map->get (p)))
{
- tree clobber = build_clobber (TREE_TYPE (*varp), CLOBBER_EOL);
+ tree clobber = build_clobber (TREE_TYPE (*varp),
+ CLOBBER_STORAGE_END);
gimple *clobber_stmt;
clobber_stmt = gimple_build_assign (*varp, clobber);
gimple_set_location (clobber_stmt, gimple_location (stmt));
@@ -5208,7 +5209,8 @@ expand_call_inline (basic_block bb, gimple *stmt, copy_body_data *id,
&& !is_gimple_reg (id->retvar)
&& !stmt_ends_bb_p (stmt))
{
- tree clobber = build_clobber (TREE_TYPE (id->retvar), CLOBBER_EOL);
+ tree clobber = build_clobber (TREE_TYPE (id->retvar),
+ CLOBBER_STORAGE_END);
gimple *clobber_stmt;
clobber_stmt = gimple_build_assign (id->retvar, clobber);
gimple_set_location (clobber_stmt, gimple_location (old_stmt));
diff --git a/gcc/tree-pretty-print.cc b/gcc/tree-pretty-print.cc
index 0dabb6d1580..cab99f9dfb6 100644
--- a/gcc/tree-pretty-print.cc
+++ b/gcc/tree-pretty-print.cc
@@ -2624,8 +2624,23 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags,
if (TREE_CLOBBER_P (node))
{
pp_string (pp, "CLOBBER");
- if (CLOBBER_KIND (node) == CLOBBER_EOL)
- pp_string (pp, "(eol)");
+ switch (CLOBBER_KIND (node))
+ {
+ case CLOBBER_STORAGE_BEGIN:
+ pp_string (pp, "(bos)");
+ break;
+ case CLOBBER_STORAGE_END:
+ pp_string (pp, "(eos)");
+ break;
+ case CLOBBER_OBJECT_BEGIN:
+ pp_string (pp, "(bob)");
+ break;
+ case CLOBBER_OBJECT_END:
+ pp_string (pp, "(eob)");
+ break;
+ default:
+ break;
+ }
}
else if (TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
|| TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
diff --git a/gcc/tree-ssa-ccp.cc b/gcc/tree-ssa-ccp.cc
index ddcbaaaa417..fab2a9b248a 100644
--- a/gcc/tree-ssa-ccp.cc
+++ b/gcc/tree-ssa-ccp.cc
@@ -2525,7 +2525,7 @@ insert_clobber_before_stack_restore (tree saved_val, tree var,
FOR_EACH_IMM_USE_STMT (stmt, iter, saved_val)
if (gimple_call_builtin_p (stmt, BUILT_IN_STACK_RESTORE))
{
- clobber = build_clobber (TREE_TYPE (var), CLOBBER_EOL);
+ clobber = build_clobber (TREE_TYPE (var), CLOBBER_STORAGE_END);
clobber_stmt = gimple_build_assign (var, clobber);
i = gsi_for_stmt (stmt);
--
2.39.3
next prev parent reply other threads:[~2023-12-12 15:25 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-03 1:18 Nathaniel Shead
2023-11-03 1:34 ` Nathaniel Shead
2023-11-27 11:08 ` Nathaniel Shead
2023-12-09 20:12 ` Jason Merrill
2023-12-10 10:22 ` Richard Biener
2023-12-10 11:21 ` Alexander Monakov
2023-12-10 15:58 ` Richard Biener
2023-12-10 18:34 ` Jason Merrill
2023-12-11 8:02 ` Richard Biener
2023-12-11 19:12 ` Jason Merrill
2023-12-11 19:17 ` Richard Biener
2023-12-11 19:21 ` Marek Polacek
2023-12-11 22:00 ` Jason Merrill
2023-12-11 22:22 ` Marek Polacek
2023-12-11 23:03 ` Jakub Jelinek
2023-12-12 11:13 ` Alexander Monakov
2023-12-12 11:15 ` Jakub Jelinek
2023-12-12 15:24 ` Jason Merrill [this message]
2023-12-12 17:50 ` Jason Merrill
2023-12-13 4:40 ` Jason Merrill
2023-12-13 16:47 ` [pushed 1/4] c++: copy location to AGGR_INIT_EXPR Jason Merrill
2023-12-13 16:47 ` [pushed 2/4] c++: constant direct-initialization [PR108243] Jason Merrill
2023-12-13 16:47 ` [pushed 3/4] c++: fix in-charge parm in constexpr Jason Merrill
2023-12-13 16:47 ` [pushed 4/4] c++: End lifetime of objects in constexpr after destructor call [PR71093] Jason Merrill
2023-12-13 18:05 ` [pushed 1/4] c++: copy location to AGGR_INIT_EXPR Patrick Palka
2023-12-13 20:06 ` [pushed] c++: TARGET_EXPR location in default arg [PR96997] Jason Merrill
2023-12-14 0:00 ` [pushed 1/4] c++: copy location to AGGR_INIT_EXPR Marek Polacek
2023-12-14 1:38 ` Jason Merrill
2023-12-14 14:25 ` Marek Polacek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9f1eaeb5-7de7-42c8-ae2a-dc74e6db99f2@redhat.com \
--to=jason@redhat.com \
--cc=amonakov@ispras.ru \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=nathanieloshead@gmail.com \
--cc=polacek@redhat.com \
--cc=rguenther@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).