public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/114347] New: wrong constant folding when casting __bf16 to int
@ 2024-03-15  4:55 eggert at cs dot ucla.edu
  2024-03-15  5:01 ` [Bug middle-end/114347] " pinskia at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: eggert at cs dot ucla.edu @ 2024-03-15  4:55 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114347
           Summary: wrong constant folding when casting __bf16 to int
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eggert at cs dot ucla.edu
  Target Milestone: ---

This is gcc (GCC) 13.2.1 20231205 (Red Hat 13.2.1-6) on Fedora 39. I found this
bug when looking into a GNU coreutils report <https://bugs.gnu.org/69770>
originally reported against Clang (Clang has a different bug).

Compile and run this program:

  __bf16 x = 257.0bf16;
  int
  main (void)
  {
    return (int) x != (int) 257.0bf16;
  }

with "gcc -O2 v.c; ./a.out; echo $?". This prints "1"; it should print "0".

The problem is that GCC constant-folds '(int) 257.0bf16' to 257. This is
incorrect, as 257.0bf16 is exactly equal to 256.0bf16, due to rounding when the
constant is parsed. The expression '(int) x' correctly yields 256 at runtime,
and 256 is not equal to the 257 incorrectly yielded by the constant folding.

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

end of thread, other threads:[~2024-03-25 22:21 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-15  4:55 [Bug c/114347] New: wrong constant folding when casting __bf16 to int eggert at cs dot ucla.edu
2024-03-15  5:01 ` [Bug middle-end/114347] " pinskia at gcc dot gnu.org
2024-03-15  5:19 ` eggert at cs dot ucla.edu
2024-03-15  9:03 ` rguenth at gcc dot gnu.org
2024-03-15 16:58 ` jsm28 at gcc dot gnu.org
2024-03-18  8:03 ` rguenth at gcc dot gnu.org
2024-03-18  8:16 ` jakub at gcc dot gnu.org
2024-03-18  8:53 ` rguenth at gcc dot gnu.org
2024-03-18  9:06 ` jakub at gcc dot gnu.org
2024-03-18  9:08 ` liuhongt at gcc dot gnu.org
2024-03-20  6:02 ` eggert at cs dot ucla.edu
2024-03-20  6:19 ` pinskia at gcc dot gnu.org
2024-03-21  0:48 ` cvs-commit at gcc dot gnu.org
2024-03-25 22:21 ` 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).