http://llvm.org/bugs/show_bug.cgi?id=15383

            Bug ID: 15383
           Summary: sanitize float-cast-overflow false positive with 255.5
                    to uint8_t?
           Product: new-bugs
           Version: trunk
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

Consider this C++:

-------------------
#include <stdint.h>

int main (void)
{
  double d = 255.5;
  uint8_t c = (uint8_t)d;

  return c;
}
-------------------

then:

$ clang++ -fsanitize=float-cast-overflow test.cxx

runtime error: value 255.5 is outside the range of representable values of type
'unsigned char'

The standard seems to say "An rvalue of a floating point type can be converted
to an rvalue of an integer type. The conversion truncates; that is, the
fractional part is discarded. The behavior is undefined if the ***truncated***
value cannot be represented in the destination type."  (emphasis mine)

So I believe clang is wrong to warn here.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to