[LLVMbugs] [Bug 15383] New: sanitize float-cast-overflow false positive with 255.5 to uint8_t?

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Feb 27 13:25:04 PST 2013


            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: unassignedbugs at nondot.org
          Reporter: sean at rogue-research.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Consider this C++:

#include <stdint.h>

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

  return c;


$ 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130227/017c00e6/attachment.html>

More information about the llvm-bugs mailing list