public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "arek_koz at o2 dot pl" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/99494] New: isfinite gets optimized away with -Ofast
Date: Tue, 09 Mar 2021 19:01:53 +0000	[thread overview]
Message-ID: <bug-99494-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 99494
           Summary: isfinite gets optimized away with -Ofast
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arek_koz at o2 dot pl
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu
            Target: x86_64-pc-linux-gnu
             Build: x86_64-pc-linux-gnu

Created attachment 50342
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50342&action=edit
stripped _Py_HashDouble

CPython compiled with -Ofast hangs forever on python -c 'hash(float("inf"))'.

Attached is a program based on stripped _Py_HashDouble from CPython sources.

It should print 314159 when it reads an infinite number from the input.
It always prints 1 instead (the function gets reduced to "return 1").

When replacing -Ofast with -O3, the problem is gone. Likely to appear on other
build/host/target configurations.

Version: gcc (Gentoo 10.2.0-r5 p6) 10.2.0
Target architecture: x86_64 (generic)
GCC is compiled to execute on: x86_64 (znver2)
Invoked command: x86_64-pc-linux-gnu-gcc -Ofast -o bug bug.c

My best guess:
GCC -Ofast assumes that isfinite(v) is always true for any double v.

             reply	other threads:[~2021-03-09 19:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-09 19:01 arek_koz at o2 dot pl [this message]
2021-03-09 19:11 ` [Bug c/99494] " schwab@linux-m68k.org
2021-03-09 19:14 ` arek_koz at o2 dot pl

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-99494-4@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).