[Bug 33459] New: p static_cast<int16_t>(...) has inconsistent output

Bug ID 33459
Summary p static_cast<int16_t>(…) has inconsistent output
Product lldb
Version 3.9
Hardware PC
OS All
Status NEW
Severity enhancement
Priority P
Component All Bugs
Assignee lldb-dev@lists.llvm.org
Reporter vince@nethacker.com
CC llvm-bugs@lists.llvm.org

(lldb) version
lldb version 3.9.0 ( revision )

(lldb) p r_sigma_float
(const float) $11 = 0.0500000007


(lldb) p (1.0f / (2 * r_sigma_float * r_sigma_float)) * (1<<kQ)
(float) $3 = 51199.9961


(lldb) p static_cast<int16_t>(51199.99f)
(int16_t) $1 = 32767

Technically, this is undefined but the output here matches what g++ does so I
think it's good.  Clang current returns inconsistent results.  Ideally, it
would be nice for lldb to print (undefined) or be consistent with whatever
compiler you are using.  I'm hoping to get clang's behavior changed:

(lldb) p static_cast<int16_t>((1.0f / (2 * r_sigma_float * r_sigma_float)) *
(int16_t) $2 = -14337

Again this is undefined but it is inconsistent with the previous behavior so I
would call it a bug.