[Bug c/86113] New: __builtin_nan has "const" attribute

gfalcon at google dot com gcc-bugzilla@gcc.gnu.org
Mon Jun 11 21:23:00 GMT 2018


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

            Bug ID: 86113
           Summary: __builtin_nan has "const" attribute
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gfalcon at google dot com
  Target Milestone: ---

__builtin_nan and friends incorrectly have ATTR_CONST.  This leads the
optimizer into generating incorrect code.  This issue also infects std::nan()
and friends.

The two functions below return different answers in -O1 and above:

double a() {
  char buf[4];
  buf[0] = buf[1] = buf[2] = '9';
  buf[3] = '\0';
  return nan(buf);
}

double b() { return nan("999"); }

In a(), the optimizer thinks that nothing reads the contents of `buf`, and
eliminates the assignments.  See https://godbolt.org/g/RGHnXQ.


More information about the Gcc-bugs mailing list