[llvm-bugs] [Bug 46095] New: Clang can not detect runtime error of invalid float cast

via llvm-bugs llvm-bugs at lists.llvm.org
Wed May 27 02:40:51 PDT 2020


            Bug ID: 46095
           Summary: Clang can not detect runtime error of invalid float
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: haoxintu at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

This case test.cc


int main(){
    double n = 10e50;
    float m = (float)n; // Error: 10e50 can't be represented as a float.
    std::cout << "ok" << std::endl;
    return 0;

$clang++-8 -w -fsanitize=float-cast-overflow test.cc ; ./a.out 
test.cc:5:22: runtime error: 1e+51 is outside the range of representable values
of type 'float'

$clang++-9 -w -fsanitize=float-cast-overflow test.cc ; ./a.out 

$clang++-10 -w -fsanitize=float-cast-overflow test.cc ; ./a.out 

$clang++-trunk -w -fsanitize=float-cast-overflow test.cc ; ./a.out 

My clang-trunk version is
$clang++-trunk --version
clang version 11.0.0 (https://github.com/llvm/llvm-project
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/haoxin/compilers/llvm-clang/llvm-project/build/bin

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/20200527/d788525e/attachment.html>

More information about the llvm-bugs mailing list