diff options
| author | Craig Topper <craig.topper@gmail.com> | 2017-05-12 16:28:21 +0000 |
|---|---|---|
| committer | Craig Topper <craig.topper@gmail.com> | 2017-05-12 16:28:21 +0000 |
| commit | 51416caf343a56754c06f64843eda12698f1a91a (patch) | |
| tree | e03317b73830f3387d3bec17cbc43b76b5599281 | |
| parent | ddb8e06a8e5cf4964d1f87e51ba5541235dd6a48 (diff) | |
| download | bcm5719-llvm-51416caf343a56754c06f64843eda12698f1a91a.tar.gz bcm5719-llvm-51416caf343a56754c06f64843eda12698f1a91a.zip | |
[APInt] Use MathExtras.h BitsToFloat/Double and Float/DoubleToBits instead of type punning through a union
The functions in MathExtras.h uses a safer memcpy instead of going through a union.
Differential Revision: https://reviews.llvm.org/D33116
llvm-svn: 302916
| -rw-r--r-- | llvm/include/llvm/ADT/APInt.h | 28 |
1 files changed, 4 insertions, 24 deletions
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h index 52f1c0892c2..94fbd1a29bf 100644 --- a/llvm/include/llvm/ADT/APInt.h +++ b/llvm/include/llvm/ADT/APInt.h @@ -1657,12 +1657,7 @@ public: /// re-interprets the bits as a double. Note that it is valid to do this on /// any bit width. Exactly 64 bits will be translated. double bitsToDouble() const { - union { - uint64_t I; - double D; - } T; - T.I = (isSingleWord() ? U.VAL : U.pVal[0]); - return T.D; + return BitsToDouble(getWord(0)); } /// \brief Converts APInt bits to a double @@ -1671,12 +1666,7 @@ public: /// re-interprets the bits as a float. Note that it is valid to do this on /// any bit width. Exactly 32 bits will be translated. float bitsToFloat() const { - union { - unsigned I; - float F; - } T; - T.I = unsigned((isSingleWord() ? U.VAL : U.pVal[0])); - return T.F; + return BitsToFloat(getWord(0)); } /// \brief Converts a double to APInt bits. @@ -1684,12 +1674,7 @@ public: /// The conversion does not do a translation from double to integer, it just /// re-interprets the bits of the double. static APInt doubleToBits(double V) { - union { - uint64_t I; - double D; - } T; - T.D = V; - return APInt(sizeof T * CHAR_BIT, T.I); + return APInt(sizeof(double) * CHAR_BIT, DoubleToBits(V)); } /// \brief Converts a float to APInt bits. @@ -1697,12 +1682,7 @@ public: /// The conversion does not do a translation from float to integer, it just /// re-interprets the bits of the float. static APInt floatToBits(float V) { - union { - unsigned I; - float F; - } T; - T.F = V; - return APInt(sizeof T * CHAR_BIT, T.I); + return APInt(sizeof(float) * CHAR_BIT, FloatToBits(V)); } /// @} |

