From: Marek Polacek <polacek@redhat.com>
To: Martin Sebor <msebor@gmail.com>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] unshare expressions in attribute arguments
Date: Fri, 20 Nov 2020 14:29:51 -0500 [thread overview]
Message-ID: <20201120192951.GE3996@redhat.com> (raw)
In-Reply-To: <56b14df5-16a6-58ae-519a-7d2a9c84e948@gmail.com>
On Fri, Nov 20, 2020 at 12:00:58PM -0700, Martin Sebor via Gcc-patches wrote:
> To detect a subset of VLA misuses, the C front associates the bounds
> of VLAs in function argument lists with the corresponding variables
> by implicitly adding an instance of attribute access to each function
> declared to take VLAs with the bound expressions chained on the list
> of attribute arguments.
>
> Some of these expressions end up modified by the middle end, which
> results in references to nonlocal variables (and perhaps other nodes)
> used in these expression getting garbage collected. A simple example
> of this is described in pr97172.
>
> By unsharing the bound expressions the patch below prevents this from
> happening (it's not a fix for pr97172).
>
> My understanding of the details of node sharing and garbage collection
> in GCC is very limited (I didn't expect a tree to be garbage-collected
> if it's still referenced by something). Is this the right approach
> to solving this problem?
ISTM that a more natural thing would be to use build_distinct_type_copy
to copy the type you're about to modify.
> diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
> index d348e39c27a..4aea4dcafb9 100644
> --- a/gcc/c/c-decl.c
> +++ b/gcc/c/c-decl.c
> @@ -58,7 +58,7 @@ along with GCC; see the file COPYING3. If not see
> #include "c-family/name-hint.h"
> #include "c-family/known-headers.h"
> #include "c-family/c-spellcheck.h"
> -
> +#include "gimplify.h"
> #include "tree-pretty-print.h"
>
> /* In grokdeclarator, distinguish syntactic contexts of declarators. */
> @@ -5780,6 +5780,7 @@ get_parm_array_spec (const struct c_parm *parm, tree
> attrs)
> /* Each variable VLA bound is represented by the dollar
> sign. */
> spec += "$";
> + nelts = unshare_expr (nelts);
> tpbnds = tree_cons (NULL_TREE, nelts, tpbnds);
> }
> }
> @@ -5834,6 +5835,7 @@ get_parm_array_spec (const struct c_parm *parm, tree
> attrs)
>
> /* Each variable VLA bound is represented by a dollar sign. */
> spec += "$";
> + nelts = unshare_expr (nelts);
> vbchain = tree_cons (NULL_TREE, nelts, vbchain);
> }
>
Marek
next prev parent reply other threads:[~2020-11-20 19:29 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-20 19:00 Martin Sebor
2020-11-20 19:29 ` Marek Polacek [this message]
2020-11-20 20:28 ` Martin Sebor
2020-11-20 20:37 ` Jakub Jelinek
2020-11-20 21:30 ` Martin Sebor
2020-11-20 21:41 ` Jakub Jelinek
2020-11-20 21:54 ` Martin Sebor
2020-11-20 21:57 ` Jakub Jelinek
2020-11-20 22:44 ` Martin Sebor
2020-11-21 8:01 ` Jakub Jelinek
2020-11-23 17:03 ` Martin Sebor
2020-11-23 17:30 ` Jakub Jelinek
2020-11-23 18:08 ` Martin Sebor
2020-11-23 18:21 ` Jakub Jelinek
2020-11-23 18:51 ` Martin Sebor
2020-11-23 23:51 ` Joseph Myers
2020-11-22 4:01 ` Jeff Law
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=20201120192951.GE3996@redhat.com \
--to=polacek@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=msebor@gmail.com \
/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).