public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++: Implement C++26 P2809R3 - Trivial infinite loops are not Undefined Behavior
Date: Wed, 3 Apr 2024 16:48:27 -0400	[thread overview]
Message-ID: <01650082-6256-4d59-8426-5f444fc96a8d@redhat.com> (raw)
In-Reply-To: <Zg2rIFMOTIGy9rL0@tucnak>

On 4/3/24 15:16, Jakub Jelinek wrote:
> On Wed, Apr 03, 2024 at 12:58:12PM -0400, Jason Merrill wrote:
>> On 4/3/24 12:42, Jakub Jelinek wrote:
>>> On Wed, Apr 03, 2024 at 12:07:48PM -0400, Jason Merrill wrote:
>>>> Using std::is_constant_evaluated directly in a loop condition is, as the
>>>> paper says, unlikely and "horrendous code", so I'm not concerned about
>>>> surprising effects, though I guess we should check for it with
>>>> maybe_warn_for_constant_evaluated.
>>>
>>> Ok, though guess the question is what to say about it.
>>> Because unlike the existing cases in maybe_warn_for_constant_evaluated
>>> where it always evaluates to true or always to false depending on where,
>>> in the trivial empty iteration statements it evaluates to always true or
>>> always false depending or sometimes true, sometimes false, depending on
>>> if the condition is a constant expression that evaluates to true (then it is
>>> always true), or if in immediate function (also always true), or if not
>>> in constexpr function (then always false), or in constexpr function (then
>>> it might be true or false).
>>> Not sure how exactly to word that.
>>> Maybe just say that it is horrendous code to use std::is_constant_evaluated
>>> () in trivial empty iteration statement conditions ;)
>>
>> Maybe if the condition constant-evaluates to true, warn something like
>> "%<std::is_constant_evaluated%> always constant-evaluates to true in the
>> condition of a trivially empty iteration statement"?
> 
> Given the mails on core about this, isn't it actually the case that not all
> "trivial infinite loops" actually loop at all or if they loop, don't loop
> infinitely?
> I.e. what I wrote in the patch would be wrong and that generally we need to
> use ANNOTATE_EXPR in some cases?

Apparently so.

> As in, for trivially empty iteration statements try to evaluate the
> maybe_const_value evaluate condition with mce_true, if it yields true,
> try to maybe_const_value evaluate condition with mce_false, if it also
> yields true, replace it with true, but if the former returns true and
> the latter isn't a constant expression or returns false mark the loop with
> ANNOTATE_EXPR as infinite loop regardless of -ffinite-loops and actually
> keep invoking the condition in there?

Sure.

Jason


      reply	other threads:[~2024-04-03 20:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-03  7:25 Jakub Jelinek
2024-04-03  7:35 ` Richard Biener
2024-04-03  7:46   ` Jakub Jelinek
2024-04-03 16:07 ` Jason Merrill
2024-04-03 16:42   ` Jakub Jelinek
2024-04-03 16:58     ` Jason Merrill
2024-04-03 19:16       ` Jakub Jelinek
2024-04-03 20:48         ` Jason Merrill [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=01650082-6256-4d59-8426-5f444fc96a8d@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@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).