From: Jason Merrill <jason@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: Richard Biener <rguenther@suse.de>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++, v2: Further address_compare fixes [PR89074]
Date: Thu, 3 Feb 2022 16:04:57 -0500 [thread overview]
Message-ID: <14f595e5-6158-6305-ef50-ac8d5f2b3c87@redhat.com> (raw)
In-Reply-To: <20220203203320.GV2646553@tucnak>
On 2/3/22 15:33, Jakub Jelinek wrote:
> On Thu, Feb 03, 2022 at 03:07:03PM -0500, Jason Merrill wrote:
>>> --- gcc/fold-const.h.jj 2022-02-01 20:10:51.235856007 +0100
>>> +++ gcc/fold-const.h 2022-02-03 15:02:02.700228631 +0100
>>> -/* Non-zero if we are folding constants inside an initializer; zero
>>> - otherwise. */
>>> +/* Nonzero if we are folding constants inside an initializer or a C++
>>> + manifestly-constant-evaluated context; zero otherwise.
>>> + Should be used when folding in initializer enables additional
>>> + optimizations. */
>>> extern int folding_initializer;
>>> +/* Nonzer of we are folding C++ manifestly-constant-evaluated context; zero
>>
>> "Nonzero if"
>
> Oops, thanks for catching it.
>
>>> + if (!folding_cxx_constexpr
>>> + && ((DECL_P (base0) && TREE_CODE (base1) == STRING_CST)
>>> + || (TREE_CODE (base0) == STRING_CST && DECL_P (base1))
>>> + || (TREE_CODE (base0) == STRING_CST
>>> + && TREE_CODE (base1) == STRING_CST
>>> + && ioff0 >= 0 && ioff1 >= 0
>>> + && ioff0 < TREE_STRING_LENGTH (base0)
>>> + && ioff1 < TREE_STRING_LENGTH (base1)
>>> + /* This is a too conservative test that the STRING_CSTs
>>> + will not end up being string-merged. */
>>> + && strncmp (TREE_STRING_POINTER (base0) + ioff0,
>>> + TREE_STRING_POINTER (base1) + ioff1,
>>> + MIN (TREE_STRING_LENGTH (base0) - ioff0,
>>> + TREE_STRING_LENGTH (base1) - ioff1)) != 0)))
>>> ;
>>> - else if (!DECL_P (base0) || !DECL_P (base1))
>>> + /* Punt on non-zero offsets from functions. */
>>> + else if ((TREE_CODE (base0) == FUNCTION_DECL && ioff0)
>>> + || (TREE_CODE (base1) == FUNCTION_DECL && ioff1))
>>> + return 2;
>>> + else if ((!DECL_P (base0)
>>> + && (!folding_cxx_constexpr || TREE_CODE (base0) != STRING_CST))
>>> + || (!DECL_P (base1)
>>> + && (!folding_cxx_constexpr || TREE_CODE (base1) != STRING_CST)))
>>
>> I think it would be clearer to leave the !DECL_P case alone and add
>>
>> /* In C++ it is unspecified, and so non-constant, whether two
>> equivalent strings have the same address. */
>> else if (folding_cxx_constexpr
>> && (TREE_CODE (base0) == STRING_CST
>> || TREE_CODE (base1) == STRING_CST)
>
> The point was to let the first if handle for
> !folding_cxx_constexpr the cases with STRING_CST
> as one or both operands and if that falls through, return 2.
Ah, I see. And then for folding_cxx_constexpr you have your new code
toward the bottom of the function that can say they're unequal in some
cases. Can you combine the STRING_CST handling for both values of
folding_cxx_constexpr instead of having them so far apart?
Jason
next prev parent reply other threads:[~2022-02-03 21:05 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-06 9:24 [PATCH] c++: Reject in constant evaluation address comparisons of start of one var and end of another [PR89074] Jakub Jelinek
2022-01-10 14:10 ` Richard Biener
2022-01-11 3:24 ` Andrew Pinski
2022-01-13 17:35 ` Patch ping (Re: [PATCH] c++: Reject in constant evaluation address comparisons of start of one var and end of another [PR89074]) Jakub Jelinek
2022-01-13 21:18 ` [PATCH] c++: Reject in constant evaluation address comparisons of start of one var and end of another [PR89074] Jason Merrill
2022-01-18 10:17 ` [PATCH] c++: Further address_compare fixes [PR89074] Jakub Jelinek
2022-01-18 12:30 ` Jakub Jelinek
2022-01-18 16:25 ` Jason Merrill
2022-01-18 16:40 ` Jakub Jelinek
2022-01-18 16:56 ` Jason Merrill
2022-02-03 15:52 ` [PATCH] c++, v2: " Jakub Jelinek
2022-02-03 20:07 ` Jason Merrill
2022-02-03 20:33 ` Jakub Jelinek
2022-02-03 21:04 ` Jason Merrill [this message]
2022-02-03 21:18 ` Jakub Jelinek
2022-02-03 21:34 ` Jason Merrill
2022-02-04 13:41 ` [PATCH] c++, v3: " Jakub Jelinek
2022-02-04 21:42 ` Jason Merrill
2022-02-04 23:02 ` Jakub Jelinek
2022-02-05 12:17 ` [PATCH] c++, v4: " Jakub Jelinek
2022-02-05 13:54 ` Jason Merrill
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=14f595e5-6158-6305-ef50-ac8d5f2b3c87@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=rguenther@suse.de \
/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).