public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "shaohua.li at inf dot ethz.ch" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/103406] New: gcc -O0 behaves differently on "DBL_MAX related operations" than gcc -O1 and above
Date: Wed, 24 Nov 2021 11:09:30 +0000	[thread overview]
Message-ID: <bug-103406-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 103406
           Summary: gcc -O0 behaves differently on "DBL_MAX related
                    operations" than gcc -O1 and above
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

Hi there,

I found that for a piece of code, gcc would give out different results when
compiled with different opt flags.

- gcc version: 11.1.0

- Platform: Ubuntu 20.04, x86_64

$gcc a.c -O0; ./a.out
nan
$
$
$gcc a.c -O1; ./a.out
-nan
$
$
$cat a.c

#include <stdio.h>
#include <float.h>

#define INFINITY (DBL_MAX+DBL_MAX)
#define NAN (INFINITY-INFINITY)

void main() {
  double x = -NAN;
  double y = NAN;
  double z = x + y;
  printf("%lf\n", z);
}

             reply	other threads:[~2021-11-24 11:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-24 11:09 shaohua.li at inf dot ethz.ch [this message]
2021-11-24 11:21 ` [Bug c/103406] " pinskia at gcc dot gnu.org
2021-11-24 11:23 ` ubizjak at gmail dot com
2021-11-24 11:29 ` pinskia at gcc dot gnu.org
2021-11-24 11:54 ` rguenth at gcc dot gnu.org
2021-11-24 12:01 ` rguenth at gcc dot gnu.org
2021-11-24 12:02 ` rguenth at gcc dot gnu.org
2021-11-24 12:03 ` [Bug middle-end/103406] [12 Regression] " rguenth at gcc dot gnu.org
2021-11-24 12:29 ` roger at nextmovesoftware dot com
2021-11-24 13:02 ` rguenth at gcc dot gnu.org
2021-11-24 13:04 ` rguenth at gcc dot gnu.org
2021-11-24 13:05 ` rguenth at gcc dot gnu.org
2021-11-24 22:22 ` joseph at codesourcery dot com
2021-11-25 19:04 ` cvs-commit at gcc dot gnu.org
2021-11-25 19:40 ` [Bug middle-end/103406] " roger at nextmovesoftware dot com
2021-11-25 20:29 ` joseph at codesourcery dot com
2021-11-26 17:58 ` roger at nextmovesoftware dot com

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