[PATCH] [libcxx] Consolidate new/delete replacement in tests and disable it when using sanitizers.
Eric Fiselier
eric at efcs.ca
Tue Dec 9 12:21:05 PST 2014
================
Comment at: test/support/count_new.hpp:8
@@ +7,3 @@
+
+int new_called = 0;
+int delete_called = 0;
----------------
jroelofs wrote:
> For avoidance of macros, how about something like this:
>
> class MemCounter {
> private:
> int new_called;
> public:
> bool checkNewCallsEq(int N) {
> #if !__has_feature(address_sanitizer) && !__has_feature(memory_sanitizer)
> return new_called == N;
> #else
> return true;
> #endif
> }
> };
>
> MemCounter globalMemCounter;
>
> #if !__has_feature(address_sanitizer) && !__has_feature(memory_sanitizer)
> void* operator new(std::size_t s) throw(std::bad_alloc) {
> ...
> }
> #endif
>
> And then in the individual tests:
>
> assert(globalMemCounter.checkNewCallsEq(0));
>
> And then if we want to be even more fancy later on, the MemCounter objects could be set up to count only within a scope by allowing them to register with each other to listen for these events. That seems like it'd be beneficial for at least `utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp`, and possibly others.
I like it! Much cleaner than what we have now. Thanks!
http://reviews.llvm.org/D6562
More information about the cfe-commits
mailing list