From: Jason Merrill <jason@redhat.com>
To: Martin Sebor <msebor@gmail.com>, Jeff Law <law@redhat.com>,
Gcc Patch List <gcc-patches@gcc.gnu.org>
Cc: Marek Polacek <polacek@redhat.com>, Jakub Jelinek <jakub@redhat.com>
Subject: Re: [PATCH] c++/67376 Comparison with pointer to past-the-end, of array fails inside constant expression
Date: Wed, 30 Mar 2016 20:19:00 -0000 [thread overview]
Message-ID: <56FC2847.8000705@redhat.com> (raw)
In-Reply-To: <56FBFFB2.2060301@gmail.com>
On 03/30/2016 12:32 PM, Martin Sebor wrote:
> On 03/30/2016 09:30 AM, Jason Merrill wrote:
>> On 03/29/2016 11:57 PM, Martin Sebor wrote:
>>>> Are we confident that arr[0] won't make it here as POINTER_PLUS_EXPR or
>>>> some such?
>>>
>>> I'm as confident as I can be given that this is my first time
>>> working in this area. Which piece of code or what assumption
>>> in particular are you concerned about?
>>
>> I want to be sure that we don't fold these conditions to false.
>>
>> constexpr int *ip = 0;
>> constexpr struct A { int ar[3]; } *ap = 0;
>>
>> static_assert(&ip[0] == 0);
>> static_assert(&(ap->ar[0]) == 0);
>
> I see. Thanks for clarifying. The asserts pass. The expressions
> are folded earlier on (in fact, as we discussed, the second one
> too early and is accepted even though it's undefined and should be
> rejected in a constexpr context) and never reach fold_comparison.
Good, then let's add at least the first to one of the tests.
> + /* Avoid folding references to struct members at offset 0 to
> + prevent tests like '&ptr->firstmember == 0' from getting
> + eliminated. When ptr is null, although the -> expression
> + is strictly speaking invalid, GCC retains it as a matter
> + of QoI. See PR c/44555. */
> + && (TREE_CODE (op0) != ADDR_EXPR
> + || TREE_CODE (TREE_OPERAND (op0, 0)) != COMPONENT_REF
> + || compare_tree_int (DECL_FIELD_OFFSET ((TREE_OPERAND
> + (TREE_OPERAND (op0, 0), 1))), 0))
Can we look at offset/bitpos here rather than examine the tree structure
of op0? get_inner_reference already examined it for us.
Also, it looks like you aren't handling the case with the operands
switched, i.e. 0 == p and such.
Jason
next prev parent reply other threads:[~2016-03-30 19:26 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-14 21:25 Martin Sebor
2016-03-14 22:13 ` Jakub Jelinek
2016-03-16 19:38 ` Jeff Law
2016-03-16 22:53 ` Jakub Jelinek
2016-03-16 19:53 ` Jeff Law
2016-03-17 21:35 ` Martin Sebor
2016-03-18 17:48 ` Jeff Law
2016-03-21 17:55 ` Jason Merrill
2016-03-21 22:13 ` Jeff Law
2016-03-22 19:10 ` Jason Merrill
2016-03-22 20:38 ` Martin Sebor
2016-03-23 20:41 ` Jason Merrill
2016-03-28 23:20 ` Martin Sebor
2016-03-29 19:07 ` Jason Merrill
2016-03-30 5:56 ` Martin Sebor
2016-03-30 16:02 ` Jason Merrill
2016-03-30 16:58 ` Martin Sebor
2016-03-30 20:19 ` Jason Merrill [this message]
2016-03-30 23:09 ` Martin Sebor
2016-03-31 8:48 ` Jason Merrill
2016-03-31 19:30 ` Martin Sebor
2016-03-31 20:07 ` Jason Merrill
2016-05-31 20:33 ` Martin Sebor
2016-05-31 20:48 ` Jason Merrill
2016-03-31 17:53 ` Jeff Law
2016-03-18 19:13 ` 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=56FC2847.8000705@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=law@redhat.com \
--cc=msebor@gmail.com \
--cc=polacek@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).