Bug ID: 37778
           Summary: __builtin_nan incorrectly has "const" attribute
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++

In Builtins.def, __builtin_nan and friends have the "c" (const) attribute, even
though these functions access the pointed-to memory.  This leads the optimizer
into generating incorrect code.

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 __builtin_nan(buf);

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

In a(), the optimizer thinks that nothing reads the contents of `buf`, and
eliminates the assignments.  See

You are receiving this mail because:
You are on the CC list for the bug.
llvm-bugs mailing list

Reply via email to