public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/111714] New: Strange behavior when casting std::size_t to bool, UB or compiler bug?
@ 2023-10-06 13:59 carlosgalvezp at gmail dot com
  2023-10-06 15:02 ` [Bug c++/111714] " rguenth at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: carlosgalvezp at gmail dot com @ 2023-10-06 13:59 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111714
           Summary: Strange behavior when casting std::size_t to bool, UB
                    or compiler bug?
           Product: gcc
           Version: 9.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: carlosgalvezp at gmail dot com
  Target Milestone: ---

Created attachment 56067
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56067&action=edit
Test case

Hi!

We are bumping from GCC 7.5 to 9.4 and one of our tests fail. The test works on
GCC 10 and above, as well as Clang trunk. Sanitizers (GCC and Clang) and
Valgrind don't report anything.

I have managed to create a minimal example here:
https://godbolt.org/z/3q7c4qYzE (attached to the bug as a file as well).

There's also comments about changes to the code that can make the test pass.

This smells a lot like UB, but I can't figure out what is wrong with the code.
Otherwise it could well be a compiler bug. Is there anything obvious you can
see that could explain the behavior?

Thanks!

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/111714] Strange behavior when casting std::size_t to bool, UB or compiler bug?
  2023-10-06 13:59 [Bug c++/111714] New: Strange behavior when casting std::size_t to bool, UB or compiler bug? carlosgalvezp at gmail dot com
@ 2023-10-06 15:02 ` rguenth at gcc dot gnu.org
  2023-10-06 15:19 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-06 15:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
looks like a bug in GCC 9.x, note that's EOL and thus will receive no fixes. 
You can try to bisect where it was fixed since GCC 10.1 seems to work.  There
might be a duplicate fixed bugreport for this.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/111714] Strange behavior when casting std::size_t to bool, UB or compiler bug?
  2023-10-06 13:59 [Bug c++/111714] New: Strange behavior when casting std::size_t to bool, UB or compiler bug? carlosgalvezp at gmail dot com
  2023-10-06 15:02 ` [Bug c++/111714] " rguenth at gcc dot gnu.org
@ 2023-10-06 15:19 ` pinskia at gcc dot gnu.org
  2023-10-06 16:25 ` [Bug tree-optimization/111714] " carlosgalvezp at gmail dot com
  2023-10-06 16:26 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-06 15:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
From IV-OPTs dup:
inv_expr 3:     (-(<unnamed-signed:1>) _13 - (<unnamed-signed:1>) &input) - -1
inv_expr 4:     -(<unnamed-signed:1>) _13 - (<unnamed-signed:1>) &input

That is totally bogus (that was even in GCC 8)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug tree-optimization/111714] Strange behavior when casting std::size_t to bool, UB or compiler bug?
  2023-10-06 13:59 [Bug c++/111714] New: Strange behavior when casting std::size_t to bool, UB or compiler bug? carlosgalvezp at gmail dot com
  2023-10-06 15:02 ` [Bug c++/111714] " rguenth at gcc dot gnu.org
  2023-10-06 15:19 ` pinskia at gcc dot gnu.org
@ 2023-10-06 16:25 ` carlosgalvezp at gmail dot com
  2023-10-06 16:26 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: carlosgalvezp at gmail dot com @ 2023-10-06 16:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Carlos Galvez <carlosgalvezp at gmail dot com> ---
Thanks for the quick response! Unfortunately we are stuck on GCC 9 for reasons
so I'll try to shuffle the code around a bit to make it work :)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug tree-optimization/111714] Strange behavior when casting std::size_t to bool, UB or compiler bug?
  2023-10-06 13:59 [Bug c++/111714] New: Strange behavior when casting std::size_t to bool, UB or compiler bug? carlosgalvezp at gmail dot com
                   ` (2 preceding siblings ...)
  2023-10-06 16:25 ` [Bug tree-optimization/111714] " carlosgalvezp at gmail dot com
@ 2023-10-06 16:26 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-06 16:26 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Carlos Galvez from comment #3)
> Thanks for the quick response! Unfortunately we are stuck on GCC 9 for
> reasons so I'll try to shuffle the code around a bit to make it work :)

Using -fno-ivopts is another options since that is where the bad code is
introduced.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-10-06 16:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-06 13:59 [Bug c++/111714] New: Strange behavior when casting std::size_t to bool, UB or compiler bug? carlosgalvezp at gmail dot com
2023-10-06 15:02 ` [Bug c++/111714] " rguenth at gcc dot gnu.org
2023-10-06 15:19 ` pinskia at gcc dot gnu.org
2023-10-06 16:25 ` [Bug tree-optimization/111714] " carlosgalvezp at gmail dot com
2023-10-06 16:26 ` pinskia at gcc dot gnu.org

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).