From: Martin Sebor <msebor@gmail.com>
To: Jason Merrill <jason@redhat.com>, Jeff Law <law@redhat.com>,
gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: PING [PATCH] avoid -Warray-bounds checks for vtable assignments (PR 98266)
Date: Thu, 4 Mar 2021 10:44:44 -0700 [thread overview]
Message-ID: <36cf16b0-43af-6b0d-6ce4-63339267f52a@gmail.com> (raw)
In-Reply-To: <508a5907-0645-1871-16f5-85c93c50c726@redhat.com>
On 3/3/21 10:33 PM, Jason Merrill wrote:
> On 3/3/21 6:20 PM, Martin Sebor wrote:
...
>> I see what you mean, thanks, but I can't think of a test case to
>> trigger a false negative due to the smaller offset. Any suggestions?
>
> My only ideas involve undefined behavior, casting the address to a
> pointer to an unrelated too-large class. I don't know if that would
> show up as a MEM_REF of this pattern.
Okay, let me see if I can come up with something based on that.
>
>> With more testing I also realized that focusing solely on an underlying
>> DECL like in the above doesn't prevent the warning when an object is
>> created in dynamically allocated memory or in a backing buffer. So
>> the attached revision both adjusts the offset computation upward and
>> handles all kinds of backing store and moves the logic into a helper
>> function for better readability. I've also added more tests.
>>
>> Retested on x86_64-linux.
>>
>> Thanks again for your help!
>>
>> Martin
>>
>> PS The TYPE_BINFO test isn't as quite as restrictive as I had hoped.
>> It means we consider all derived class, not just those with virtual
>> bases.
>
> It's even less restrictive than that: all C++ classes have TYPE_BINFO.
>
>> I tried also requiring BINFO_VIRTUAL_P() to be true but that
>> doesn't work.
>
> Right, BINFO_VIRTUAL_P is true for the binfo representing the virtual
> base in the inheritance hierarchy, not on the binfo for the derived class.
>
>> Using BINFO_VTABLE() does work but it still isn't the same.
>
> Indeed, virtual functions and virtual bases both cause a class to have a
> vtable. You could also check BINFO_N_BASE_BINFOS.
>
> Or not bother trying to restrict this to classes with virtual bases
> (i.e. leave the patch as it is), since the result is just as correct for
> other classes.
>
> Jason
>
I think I'll just go with this last version if you're okay with it
as is. Okay to commit?
Martin
PS Let me propose a separate patch to add some text to the BINFO
comments in tree.h to clarify the macros per the above.
next prev parent reply other threads:[~2021-03-04 17:44 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-20 0:56 Martin Sebor
2021-01-29 17:22 ` PING " Martin Sebor
2021-02-06 17:12 ` PING 2 " Martin Sebor
2021-02-08 19:59 ` Jeff Law
2021-02-08 21:56 ` Martin Sebor
2021-02-08 22:26 ` Jeff Law
2021-02-08 22:44 ` Martin Sebor
2021-02-08 23:11 ` Jeff Law
2021-02-09 17:49 ` Martin Sebor
2021-02-23 16:02 ` PING " Martin Sebor
2021-02-23 21:52 ` Jason Merrill
2021-02-23 23:07 ` Martin Sebor
2021-02-25 0:35 ` Jason Merrill
2021-03-01 23:11 ` Martin Sebor
2021-03-02 14:11 ` Jason Merrill
2021-03-03 23:20 ` Martin Sebor
2021-03-04 5:33 ` Jason Merrill
2021-03-04 17:44 ` Martin Sebor [this message]
2021-03-04 20:00 ` Jason Merrill
2021-02-25 23:47 ` Jeff Law
2021-02-26 3:56 ` Jason Merrill
2021-02-25 23:40 ` Jeff Law
2021-03-01 23:16 ` Martin Sebor
2021-02-25 23:15 ` 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=36cf16b0-43af-6b0d-6ce4-63339267f52a@gmail.com \
--to=msebor@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=law@redhat.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).