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: unassignedclangb...@nondot.org
          Reporter: gfal...@google.com
                CC: dgre...@apple.com, llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to