diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-12-11 21:23:43 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-12-11 21:23:43 +0000 |
commit | 966942da9e68b59c31ce770e7f94c55a63482c6b (patch) | |
tree | 2959506dee78911f576201904b6df9fad057367a | |
parent | 054eb6cba689feca3c5883c6e0548d4b76b9845d (diff) |
LeakDetector: Simplify code and fix comments, NFC
Rather than requiring overloads in the wrapper and the impl, just
overload the impl and use templates in the wrapper. This makes it less
error prone to add more overloads (`void *` defeats any chance the
compiler has at noticing bugs, so the easier the better).
At the same time, correct the comment that was lying about not changing
functionality for `Value`.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224058 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/IR/LeakDetector.h | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/include/llvm/IR/LeakDetector.h b/include/llvm/IR/LeakDetector.h index cb18df87586..fb3202e902a 100644 --- a/include/llvm/IR/LeakDetector.h +++ b/include/llvm/IR/LeakDetector.h @@ -34,7 +34,7 @@ struct LeakDetector { /// pointers. This should be called when objects are created, or if they are /// taken out of an owning collection. /// - static void addGarbageObject(void *Object) { + template <class T> static void addGarbageObject(T *Object) { #ifndef NDEBUG addGarbageObjectImpl(Object); #endif @@ -44,7 +44,7 @@ struct LeakDetector { /// our "garbage" objects. This should be called when an object is added to /// an "owning" collection. /// - static void removeGarbageObject(void *Object) { + template <class T> static void removeGarbageObject(T *Object) { #ifndef NDEBUG removeGarbageObjectImpl(Object); #endif @@ -63,25 +63,15 @@ struct LeakDetector { #endif } - /// Overload the normal methods to work better with Value*'s because they are - /// by far the most common in LLVM. This does not affect the actual - /// functioning of this class, it just makes the warning messages nicer. - /// - static void addGarbageObject(const Value *Object) { -#ifndef NDEBUG - addGarbageObjectImpl(Object); -#endif - } - static void removeGarbageObject(const Value *Object) { -#ifndef NDEBUG - removeGarbageObjectImpl(Object); -#endif - } - private: - // If we are debugging, the actual implementations will be called... + /// Overload the normal methods to work better with Value* because they are + /// by far the most common in LLVM. + /// + /// Besides making the warning messages nicer, this hides errors by storing + /// Value* in a different leak-detection container than other classes. static void addGarbageObjectImpl(const Value *Object); static void removeGarbageObjectImpl(const Value *Object); + static void addGarbageObjectImpl(void *Object); static void removeGarbageObjectImpl(void *Object); static void checkForGarbageImpl(LLVMContext &C, const std::string &Message); |