diff options
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/include/llvm/ADT/APFloat.h | 3 | ||||
-rw-r--r-- | llvm/include/llvm/ADT/APInt.h | 5 | ||||
-rw-r--r-- | llvm/lib/Support/APFloat.cpp | 2 |
3 files changed, 8 insertions, 2 deletions
diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h index 64e56a0ef6a..33f997e1734 100644 --- a/llvm/include/llvm/ADT/APFloat.h +++ b/llvm/include/llvm/ADT/APFloat.h @@ -201,6 +201,9 @@ public: /// @} + /// \brief Returns whether this instance allocated memory. + bool needsCleanup() const { return partCount() > 1; } + /// \name Convenience "constructors" /// @{ diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h index a9df4036be2..e5797b8be23 100644 --- a/llvm/include/llvm/ADT/APInt.h +++ b/llvm/include/llvm/ADT/APInt.h @@ -293,7 +293,7 @@ public: /// \brief Destructor. ~APInt() { - if (!isSingleWord()) + if (needsCleanup()) delete[] pVal; } @@ -303,6 +303,9 @@ public: /// method Read). explicit APInt() : BitWidth(1) {} + /// \brief Returns whether this instance allocated memory. + bool needsCleanup() const { return !isSingleWord(); } + /// Used to insert APInt objects, or objects that contain APInt objects, into /// FoldingSets. void Profile(FoldingSetNodeID &id) const; diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp index 16586fbc9e8..2ad66c5687c 100644 --- a/llvm/lib/Support/APFloat.cpp +++ b/llvm/lib/Support/APFloat.cpp @@ -580,7 +580,7 @@ APFloat::initialize(const fltSemantics *ourSemantics) void APFloat::freeSignificand() { - if (partCount() > 1) + if (needsCleanup()) delete [] significand.parts; } |