public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Siddhesh Poyarekar <siddhesh@gotplt.org>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] tree-object-size: Support strndup and strdup
Date: Fri, 23 Sep 2022 15:02:54 +0200	[thread overview]
Message-ID: <Yy2ufq1so5ZRbjuX@tucnak> (raw)
In-Reply-To: <a1577272-5276-104d-f4f5-fe1c167be702@gotplt.org>

On Thu, Sep 22, 2022 at 11:26:29AM -0400, Siddhesh Poyarekar wrote:
> On 2022-09-22 09:02, Jakub Jelinek wrote:
> > On Mon, Aug 15, 2022 at 03:23:11PM -0400, Siddhesh Poyarekar wrote:
> > > --- a/gcc/tree-object-size.cc
> > > +++ b/gcc/tree-object-size.cc
> > > @@ -495,6 +495,18 @@ decl_init_size (tree decl, bool min)
> > >     return size;
> > >   }
> > > +/* Get the outermost object that PTR may point into.  */
> > > +
> > > +static tree
> > > +get_whole_object (const_tree ptr)
> > > +{
> > > +  tree pt_var = TREE_OPERAND (ptr, 0);
> > > +  while (handled_component_p (pt_var))
> > > +    pt_var = TREE_OPERAND (pt_var, 0);
> > > +
> > > +  return pt_var;
> > > +}
> > 
> > Not sure why you want a new function for this.
> > This is essentially get_base_address (TREE_OPERAND (ptr, 0)).
> 
> Oh, so can addr_object_size be simplified to use get_base_address too?

You can try.  As you can see in get_base_address, that function
handles something that the above doesn't (looking through some MEM_REFs too).

> > Even if c_strlen (src, 1) is constant, I don't see what you can assume
> > for object size of strndup ("abcd\0efgh", n); for minimum, except 1.
> 
> Can't we assume MIN(5, n) for STRING_CST?

If you mean MIN(5, n + 1), for c_strlen constant yes, but say if you have
strndup (&"abcd\0efgh"[i], n); you can't just from seeing a base address
being a STRING_CST with certain length assume anything than 1.

> For ARRAY_REFs, it may end up being MIN(array_size, n) and not account for

No, for non-OST_MINIMUM array size of objects (or string literals) containing
the strings is relevant and you can indeed use MIN(__b{d}os (src), n + 1)
as maximum.  But for the minimum, the object size is irrelevant, you don't
know where in the string there are '\0's and they could appear anywhere
(unless you do string length range analysis).  With c_strlen on src
returning constant you know the exact string length and so you can use
MIN (c_strlen (src, 1) + 1, n + 1) as both minimum and maximum, but in all
other cases, 1 is the safe answer.

	Jakub


  reply	other threads:[~2022-09-23 13:03 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-15 19:23 Siddhesh Poyarekar
2022-08-29 14:16 ` Siddhesh Poyarekar
2022-09-07 19:21   ` Siddhesh Poyarekar
2022-09-15 14:00     ` Siddhesh Poyarekar
2022-09-22 13:02 ` Jakub Jelinek
2022-09-22 15:26   ` Siddhesh Poyarekar
2022-09-23 13:02     ` Jakub Jelinek [this message]
2022-11-02 22:30       ` Siddhesh Poyarekar
2022-11-04 12:48 ` [PATCH v2] " Siddhesh Poyarekar
2022-11-04 13:43   ` Prathamesh Kulkarni
2022-11-04 13:47     ` Siddhesh Poyarekar
2022-11-17 19:47   ` Siddhesh Poyarekar
2022-11-20 15:42   ` Jeff Law
2022-11-21 14:27     ` Siddhesh Poyarekar
2022-11-22 20:43       ` Jeff Law
2022-11-22 23:13         ` Siddhesh Poyarekar

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=Yy2ufq1so5ZRbjuX@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=siddhesh@gotplt.org \
    /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).