[llvm-bugs] [Bug 37778] New: __builtin_nan incorrectly has "const" attribute

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jun 12 04:15:39 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=37778

            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++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: gfalcon at google.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

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 https://godbolt.org/g/sdn5Mh.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180612/8791350d/attachment.html>


More information about the llvm-bugs mailing list