public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Siddhesh Poyarekar <siddhesh@gotplt.org>
To: Jeff Law <jeffreyalaw@gmail.com>, gcc-patches@gcc.gnu.org
Cc: jakub@redhat.com
Subject: Re: [PATCH v2] tree-object-size: Support strndup and strdup
Date: Tue, 22 Nov 2022 18:13:40 -0500	[thread overview]
Message-ID: <6f7c019b-d940-f2a6-3db0-21486fb0e6a2@gotplt.org> (raw)
In-Reply-To: <d25526c3-ecaf-cf63-e90f-383d182cfe46@gmail.com>

On 2022-11-22 15:43, Jeff Law wrote:
> 
> On 11/21/22 07:27, Siddhesh Poyarekar wrote:
>> On 2022-11-20 10:42, Jeff Law wrote:
>>>
>>> On 11/4/22 06:48, Siddhesh Poyarekar wrote:
>>>> Use string length of input to strdup to determine the usable size of 
>>>> the
>>>> resulting object.  Avoid doing the same for strndup since there's a
>>>> chance that the input may be too large, resulting in an unnecessary
>>>> overhead or worse, the input may not be NULL terminated, resulting in a
>>>> crash where there would otherwise have been none.
>>>>
>>>> gcc/ChangeLog:
>>>>
>>>>     * tree-object-size.cc (todo): New variable.
>>>>     (object_sizes_execute): Use it.
>>>>     (strdup_object_size): New function.
>>>>     (call_object_size): Use it.
>>>>
>>>> gcc/testsuite/ChangeLog:
>>>>
>>>>     * gcc.dg/builtin-dynamic-object-size-0.c (test_strdup,
>>>>     test_strndup, test_strdup_min, test_strndup_min): New tests.
>>>>     (main): Call them.
>>>>     * gcc.dg/builtin-dynamic-object-size-1.c: Silence overread
>>>>     warnings.
>>>>     * gcc.dg/builtin-dynamic-object-size-2.c: Likewise.
>>>>     * gcc.dg/builtin-dynamic-object-size-3.c: Likewise.
>>>>     * gcc.dg/builtin-dynamic-object-size-4.c: Likewise.
>>>>     * gcc.dg/builtin-object-size-1.c: Silence overread warnings.
>>>>     Declare free, strdup and strndup.
>>>>     (test11): New test.
>>>>     (main): Call it.
>>>>     * gcc.dg/builtin-object-size-2.c: Silence overread warnings.
>>>>     Declare free, strdup and strndup.
>>>>     (test9): New test.
>>>>     (main): Call it.
>>>>     * gcc.dg/builtin-object-size-3.c: Silence overread warnings.
>>>>     Declare free, strdup and strndup.
>>>>     (test11): New test.
>>>>     (main): Call it.
>>>>     * gcc.dg/builtin-object-size-4.c: Silence overread warnings.
>>>>     Declare free, strdup and strndup.
>>>>     (test9): New test.
>>>>     (main): Call it.
>>>
>>> I'm struggling to see how the SSA updating is correct.  Yes we need 
>>> to update the virtuals due to the introduction of the call to strlen, 
>>> particularly when SRC is not a string constant.  But do we need to do 
>>> more?
>>>
>>> Don't we end up gimplifying the 1 + strlenfn (src) expression? Can 
>>> that possibly create new SSA_NAMEs?  Do those need to be put into SSA 
>>> form? I feel like I'm missing something here...
>>
>> We do all of that manually in gimplify_size_expressions, the only 
>> thing left to do is updating virtuals AFAICT.
> 
> I guess it's actually buried down in force_gimple_operand and I guess 
> for temporaries they're not going to be alive across the new gimple 
> sequence and each destination gets its own SSA_NAME, so it ought to be 
> safe.  Just had to work a bit further through things.
> 
> OK for the trunk.

Thanks, pushed with the trivial fixup that Prathamesh suggested, i.e. 
replaced 'if (!strndup)' with 'else'.

Sid

      reply	other threads:[~2022-11-22 23:13 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-15 19:23 [PATCH] " 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
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 [this message]

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=6f7c019b-d940-f2a6-3db0-21486fb0e6a2@gotplt.org \
    --to=siddhesh@gotplt.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jeffreyalaw@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).