public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "amacleod at redhat dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/101862] [C, C++] Potential '?:' diagnostic for always-true expressions in boolean context
Date: Wed, 11 Aug 2021 17:42:55 +0000	[thread overview]
Message-ID: <bug-101862-4-siIk64akXE@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-101862-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101862

Andrew Macleod <amacleod at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |amacleod at redhat dot com

--- Comment #1 from Andrew Macleod <amacleod at redhat dot com> ---
I'm not sure exactly what you want to do.
When we go into SSA we see:

  <bb 12> :
  _8 = arr[i_15];
  i.1_9 = (unsigned int) i_15;
  _10 = i.1_9 & 1;
  _11 = _10 != 0;
  _12 = (int) _11;
  if (_8 == _12)
    goto <bb 13>; [INV]
  else
    goto <bb 14>; [INV]

  <bb 13> :
  iftmp.0_27 = i_15 != -1;
  goto <bb 15>; [INV]

  <bb 14> :
  iftmp.0_26 = i_15 != -2;

  <bb 15> :
  # iftmp.0_16 = PHI <iftmp.0_27(13), iftmp.0_26(14)>
  if (iftmp.0_16 != 0)
    goto <bb 17>; [INV]
  else
    goto <bb 16>; [INV]

The EVRP pass recognizes that i_15 has a range of int [0, 32], thus folds 
 # iftmp.0_16 = PHI <iftmp.0_27(13), iftmp.0_26(14)>
into
# iftmp.0_16 = PHI <1, 1>
and continues to fold away the if that leads to the assert.

This seems to be too late to determine that a warning might be appropriate..
and I'm not sure how you would figure that out from this IL.

We have to go way back before gimple before we see the conditional expression.
I see the front end generates this is the .original file:
<D.1973>:;
    {
      if (arr[i] == (((unsigned int) i & 1) != 0) ? i != -1 : i != -2)
        {
          (void) 0;
        }
      else
        {
          __assert_fail ((const char *) "arr[i] == ((i % 2) != 0) ? i + 1 : i +
2", (const char *) "as.c", 17, (const char *) &__PRETTY_FUNCTION__);
        }

but even by the .gimple listing the COND_EXPR is gone, replaced with the iftmp
sequence.  Im not sure how you would determine that this is not working as
intended.. ?  we usually rejoice when we can fold asserts away :-)

The range machinery knows what you want to know, but IM not sure how you could
use it. Its only available once we go into SSA.

  reply	other threads:[~2021-08-11 17:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-11  9:19 [Bug middle-end/101862] New: " tschwinge at gcc dot gnu.org
2021-08-11 17:42 ` amacleod at redhat dot com [this message]
2021-08-13  5:25 ` [Bug middle-end/101862] " egallager at gcc dot gnu.org
2021-08-16 10:22 ` tschwinge at gcc dot gnu.org

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=bug-101862-4-siIk64akXE@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).