[PATCH] Introduce needsCleanup() for APFloat and APInt
Manuel Klimek
klimek at google.com
Sun May 12 22:59:37 PDT 2013
This is needed so one can check if the object needs the destructor called after
its memory was freed. See http://llvm-reviews.chandlerc.com/D736 for where this
is useful.
http://llvm-reviews.chandlerc.com/D783
Files:
include/llvm/ADT/APFloat.h
include/llvm/ADT/APInt.h
lib/Support/APFloat.cpp
Index: include/llvm/ADT/APFloat.h
===================================================================
--- include/llvm/ADT/APFloat.h
+++ include/llvm/ADT/APFloat.h
@@ -190,6 +190,10 @@
APFloat(const APFloat &);
~APFloat();
+ bool needsCleanup() const {
+ return partCount() > 1;
+ }
+
// Convenience "constructors"
static APFloat getZero(const fltSemantics &Sem, bool Negative = false) {
return APFloat(Sem, fcZero, Negative);
Index: include/llvm/ADT/APInt.h
===================================================================
--- include/llvm/ADT/APInt.h
+++ include/llvm/ADT/APInt.h
@@ -283,14 +283,18 @@
/// @brief Destructor.
~APInt() {
- if (!isSingleWord())
+ if (needsCleanup())
delete [] pVal;
}
/// Default constructor that creates an uninitialized APInt. This is useful
/// for object deserialization (pair this with the static method Read).
explicit APInt() : BitWidth(1) {}
+ bool needsCleanup() const {
+ return !isSingleWord();
+ }
+
/// Profile - Used to insert APInt objects, or objects that contain APInt
/// objects, into FoldingSets.
void Profile(FoldingSetNodeID& id) const;
Index: lib/Support/APFloat.cpp
===================================================================
--- lib/Support/APFloat.cpp
+++ lib/Support/APFloat.cpp
@@ -580,7 +580,7 @@
void
APFloat::freeSignificand()
{
- if (partCount() > 1)
+ if (needsCleanup())
delete [] significand.parts;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D783.1.patch
Type: text/x-patch
Size: 1487 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130512/a49c04cd/attachment.bin>
More information about the llvm-commits
mailing list