[PATCH] D46295: [ubsan] Make the C++ code here not cast floating point values outside the range of an integer type to that integer type.
Chandler Carruth via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 30 18:07:28 PDT 2018
chandlerc created this revision.
chandlerc added a reviewer: asbirlea.
Herald added subscribers: mcrosier, sanjoy.
Instead, change the random value function to cast to the destination
type first and do the devision by 8 afterward. When the destination is
floating point this should be roughly equivalent, but when it is an
integer type it will end up truncating stuff down rather than ending up
outside the range.
Repository:
rT test-suite
https://reviews.llvm.org/D46295
Files:
Bitcode/Regression/vector_widen/driver.cpp
Bitcode/simd_ops/simd_ops.cpp
Index: Bitcode/simd_ops/simd_ops.cpp
===================================================================
--- Bitcode/simd_ops/simd_ops.cpp
+++ Bitcode/simd_ops/simd_ops.cpp
@@ -24,7 +24,7 @@
template<typename T>
T rand_value() {
- return (T)(rand() * 0.125) - 100;
+ return (T)((T)rand() / 8) - 100;
}
// Even on android, we want errors to stdout
Index: Bitcode/Regression/vector_widen/driver.cpp
===================================================================
--- Bitcode/Regression/vector_widen/driver.cpp
+++ Bitcode/Regression/vector_widen/driver.cpp
@@ -2,7 +2,7 @@
template<typename T>
T rand_value() {
- return (T)(rand() * 0.125) - 100;
+ return (T)((T)rand() / 8) - 100;
}
template<typename T>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46295.144654.patch
Type: text/x-patch
Size: 735 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180501/2986cad3/attachment.bin>
More information about the llvm-commits
mailing list