From: Martin Sebor <msebor@gmail.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: Jason Merrill <jason@redhat.com>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] handle "invisible" reference in -Wdangling-pointer (PR104436)
Date: Wed, 16 Mar 2022 09:47:00 -0600 [thread overview]
Message-ID: <5e0abe09-380b-ca37-3f93-db9c8c6d32bc@gmail.com> (raw)
In-Reply-To: <CAFiYyc2oniWX94zqerj=Vt8sduscKUv1oocp5QBUS-TkWgfkOQ@mail.gmail.com>
On 3/9/22 06:17, Richard Biener wrote:
> On Fri, Feb 11, 2022 at 12:05 AM Martin Sebor via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
>>
>> On 2/8/22 15:37, Jason Merrill wrote:
>>> On 2/8/22 16:59, Martin Sebor wrote:
>>>> Transforming a by-value arguments to by-reference as GCC does for some
>>>> class types can trigger -Wdangling-pointer when the argument is used
>>>> to store the address of a local variable. Since the stored value is
>>>> not accessible in the caller the warning is a false positive.
>>>>
>>>> The attached patch handles this case by excluding PARM_DECLs with
>>>> the DECL_BY_REFERENCE bit set from consideration.
>>>>
>>>> While testing the patch I noticed some instances of the warning are
>>>> uninitentionally duplicated as the pass runs more than once. To avoid
>>>> that, I also introduce warning suppression into the handler for this
>>>> instance of the warning. (There might still be others.)
>>>
>>> The second test should verify that we do warn about returning 't' from a
>>> function; we don't want to ignore the DECL_BY_REFERENCE RESULT_DECL.
>>
>> The indirect aggregate case isn't handled and needs more work but
>> since you brought it up I thought I should look into finishing it.
>> The attached patch #2 adds support for it. It also incorporates
>> Richard's suggestion to test PARM_DECL. Patch #2 applies on top
>> of patch #1 which is unchanged from the first revision.
>
> patch #1 would be OK if you'd do the PARM_DECL check there - I'd
> rather defer #2 to stage1.
>
> Richard.
>
>>
>> I have retested it on x86_64-linux and by building Glibc and
>> Binutils + GDB.
>>
>> If now is too late for the aggregate enhancement I'm okay with
>> deferring it until stage 1.
I committed the adjusted patch in r12-7650. I'll try to remember to
ping the second patch in stage 1.
Martin
>>
>>>
>>>> + tree var = SSA_NAME_VAR (lhs_ref.ref);
>>>> + if (DECL_BY_REFERENCE (var))
>>>> + /* Avoid by-value arguments transformed into by-reference. */
>>>> + continue;
>>>
>>> I wonder if we can we express this property of invisiref parms somewhere
>>> more general? I imagine optimizations would find it useful as well.
>>> Could pointer_query somehow treat the reference as pointing to a
>>> function-local object?
>>
>> I don't quite see where in the pointer_query class this would be
>> useful (the class also isn't used for optimization). I could add
>> a helper to the access_ref class to query this property in warning
>> code but as this is the only potential client I'm also not sure
>> that's quite what you had in mind. I'd need some guidance as to
>> what you're thinking of here.
>>
>> Martin
>>
>>
>>>
>>> I previously tried to express this by marking the reference as
>>> 'restrict', but that was wrong
>>> (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97474).
>>>
>>> Jason
>>>
prev parent reply other threads:[~2022-03-16 15:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-08 21:59 Martin Sebor
2022-02-08 22:37 ` Jason Merrill
2022-02-09 8:30 ` Richard Biener
2022-02-09 15:00 ` Jason Merrill
2022-02-10 23:04 ` Martin Sebor
2022-03-01 23:14 ` PING " Martin Sebor
2022-03-09 13:17 ` Richard Biener
2022-03-16 15:47 ` Martin Sebor [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=5e0abe09-380b-ca37-3f93-db9c8c6d32bc@gmail.com \
--to=msebor@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=richard.guenther@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).