[libcxx-commits] [libcxx] 05749ac - Revert "Move more tests to globalMemCounter and reset."

Dan Albert via libcxx-commits libcxx-commits at lists.llvm.org
Fri Mar 13 13:27:05 PDT 2020


Author: Dan Albert
Date: 2020-03-13T13:26:35-07:00
New Revision: 05749acfd36dd3276863a1b887a4762524a647bc

URL: https://github.com/llvm/llvm-project/commit/05749acfd36dd3276863a1b887a4762524a647bc
DIFF: https://github.com/llvm/llvm-project/commit/05749acfd36dd3276863a1b887a4762524a647bc.diff

LOG: Revert "Move more tests to globalMemCounter and reset."

Not all of these changes were correct. Will reland appropriate parts
in a follow up.

This reverts commit 4a792965de08fb69652370625f1aec2e87111313.

Added: 
    

Modified: 
    libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow_replace.pass.cpp
    libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_replace.pass.cpp
    libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow_replace.pass.cpp
    libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_replace.pass.cpp
    libcxx/test/std/localization/locale.stdcvt/codecvt_utf16.pass.cpp
    libcxx/test/std/localization/locale.stdcvt/codecvt_utf8.pass.cpp
    libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp
    libcxx/test/std/localization/locales/locale/locale.members/combine.pass.cpp
    libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp
    libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp
    libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp
    libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp
    libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp
    libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp
    libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow_replace.pass.cpp b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow_replace.pass.cpp
index 8d7349202673..4d90aa9a3fe0 100644
--- a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow_replace.pass.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow_replace.pass.cpp
@@ -17,9 +17,24 @@
 #include <cassert>
 #include <limits>
 
-#include "count_new.h"
 #include "test_macros.h"
 
+int new_called = 0;
+
+void* operator new(std::size_t s) TEST_THROW_SPEC(std::bad_alloc)
+{
+    ++new_called;
+    void* ret = std::malloc(s);
+    if (!ret) std::abort(); // placate MSVC's unchecked malloc warning
+    return  ret;
+}
+
+void  operator delete(void* p) TEST_NOEXCEPT
+{
+    --new_called;
+    std::free(p);
+}
+
 int A_constructed = 0;
 
 struct A
@@ -30,17 +45,15 @@ struct A
 
 int main(int, char**)
 {
-    globalMemCounter.reset();
-    assert(globalMemCounter.checkOutstandingNewEq(0));
     A *ap = new (std::nothrow) A[3];
     DoNotOptimize(ap);
     assert(ap);
     assert(A_constructed == 3);
-    assert(globalMemCounter.checkOutstandingNewNotEq(0));
+    assert(new_called);
     delete [] ap;
     DoNotOptimize(ap);
     assert(A_constructed == 0);
-    assert(globalMemCounter.checkOutstandingNewEq(0));
+    assert(!new_called);
 
   return 0;
 }

diff  --git a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_replace.pass.cpp b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_replace.pass.cpp
index cbe6577747ea..e705fc3b499f 100644
--- a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_replace.pass.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_replace.pass.cpp
@@ -18,9 +18,24 @@
 #include <cassert>
 #include <limits>
 
-#include "count_new.h"
 #include "test_macros.h"
 
+int new_called = 0;
+
+void* operator new(std::size_t s) TEST_THROW_SPEC(std::bad_alloc)
+{
+    ++new_called;
+    void* ret = std::malloc(s);
+    if (!ret) std::abort(); // placate MSVC's unchecked malloc warning
+    return  ret;
+}
+
+void  operator delete(void* p) TEST_NOEXCEPT
+{
+    --new_called;
+    std::free(p);
+}
+
 int A_constructed = 0;
 
 struct A
@@ -31,17 +46,15 @@ struct A
 
 int main(int, char**)
 {
-    globalMemCounter.reset();
-    assert(globalMemCounter.checkOutstandingNewEq(0));
     A *ap = new A[3];
     DoNotOptimize(ap);
     assert(ap);
     assert(A_constructed == 3);
-    assert(globalMemCounter.checkOutstandingNewEq(1));
+    assert(new_called == 1);
     delete [] ap;
     DoNotOptimize(ap);
     assert(A_constructed == 0);
-    assert(globalMemCounter.checkOutstandingNewEq(0));
+    assert(new_called == 0);
 
   return 0;
 }

diff  --git a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow_replace.pass.cpp b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow_replace.pass.cpp
index daaf21c1847c..1f186d8b3d17 100644
--- a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow_replace.pass.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow_replace.pass.cpp
@@ -17,9 +17,24 @@
 #include <cassert>
 #include <limits>
 
-#include "count_new.h"
 #include "test_macros.h"
 
+int new_called = 0;
+
+void* operator new(std::size_t s) TEST_THROW_SPEC(std::bad_alloc)
+{
+    ++new_called;
+    void* ret = std::malloc(s);
+    if (!ret) std::abort(); // placate MSVC's unchecked malloc warning
+    return ret;
+}
+
+void  operator delete(void* p) TEST_NOEXCEPT
+{
+    --new_called;
+    std::free(p);
+}
+
 bool A_constructed = false;
 
 struct A
@@ -30,17 +45,15 @@ struct A
 
 int main(int, char**)
 {
-    globalMemCounter.reset();
-    assert(globalMemCounter.checkOutstandingNewEq(0));
     A *ap = new (std::nothrow) A;
     DoNotOptimize(ap);
     assert(ap);
     assert(A_constructed);
-    assert(globalMemCounter.checkOutstandingNewNotEq(0));
+    assert(new_called);
     delete ap;
     DoNotOptimize(ap);
     assert(!A_constructed);
-    assert(globalMemCounter.checkOutstandingNewEq(0));
+    assert(!new_called);
 
   return 0;
 }

diff  --git a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_replace.pass.cpp b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_replace.pass.cpp
index f02e4a6e01f9..4854c2fb7761 100644
--- a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_replace.pass.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_replace.pass.cpp
@@ -16,9 +16,24 @@
 #include <cassert>
 #include <limits>
 
-#include "count_new.h"
 #include "test_macros.h"
 
+int new_called = 0;
+
+void* operator new(std::size_t s) TEST_THROW_SPEC(std::bad_alloc)
+{
+    ++new_called;
+    void* ret = std::malloc(s);
+    if (!ret) std::abort(); // placate MSVC's unchecked malloc warning
+    return ret;
+}
+
+void  operator delete(void* p) TEST_NOEXCEPT
+{
+    --new_called;
+    std::free(p);
+}
+
 bool A_constructed = false;
 
 struct A
@@ -29,17 +44,15 @@ struct A
 
 int main(int, char**)
 {
-    globalMemCounter.reset();
-    assert(globalMemCounter.checkOutstandingNewEq(0));
     A *ap = new A;
     DoNotOptimize(ap);
     assert(ap);
     assert(A_constructed);
-    assert(globalMemCounter.checkOutstandingNewEq(1));
+    assert(new_called);
     delete ap;
     DoNotOptimize(ap);
     assert(!A_constructed);
-    assert(globalMemCounter.checkOutstandingNewEq(0));
+    assert(!new_called);
 
   return 0;
 }

diff  --git a/libcxx/test/std/localization/locale.stdcvt/codecvt_utf16.pass.cpp b/libcxx/test/std/localization/locale.stdcvt/codecvt_utf16.pass.cpp
index 40f8ae299206..bb69ef1d2400 100644
--- a/libcxx/test/std/localization/locale.stdcvt/codecvt_utf16.pass.cpp
+++ b/libcxx/test/std/localization/locale.stdcvt/codecvt_utf16.pass.cpp
@@ -28,7 +28,6 @@
 
 int main(int, char**)
 {
-    globalMemCounter.reset();
     assert(globalMemCounter.checkOutstandingNewEq(0));
     {
         typedef std::codecvt_utf16<wchar_t> C;

diff  --git a/libcxx/test/std/localization/locale.stdcvt/codecvt_utf8.pass.cpp b/libcxx/test/std/localization/locale.stdcvt/codecvt_utf8.pass.cpp
index 08f98fa2999a..4fc4201ee178 100644
--- a/libcxx/test/std/localization/locale.stdcvt/codecvt_utf8.pass.cpp
+++ b/libcxx/test/std/localization/locale.stdcvt/codecvt_utf8.pass.cpp
@@ -28,7 +28,6 @@
 
 int main(int, char**)
 {
-    globalMemCounter.reset();
     assert(globalMemCounter.checkOutstandingNewEq(0));
     {
         typedef std::codecvt_utf8<wchar_t> C;

diff  --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp
index bf6355d17d15..f879afb7a2f2 100644
--- a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp
@@ -23,7 +23,6 @@
 
 int main(int, char**)
 {
-    globalMemCounter.reset();
     typedef std::wbuffer_convert<std::codecvt_utf8<wchar_t> > B;
 #if TEST_STD_VER > 11
     static_assert(!std::is_convertible<std::streambuf*, B>::value, "");

diff  --git a/libcxx/test/std/localization/locales/locale/locale.members/combine.pass.cpp b/libcxx/test/std/localization/locales/locale/locale.members/combine.pass.cpp
index 8a908b58271c..68c0438abb7c 100644
--- a/libcxx/test/std/localization/locales/locale/locale.members/combine.pass.cpp
+++ b/libcxx/test/std/localization/locales/locale/locale.members/combine.pass.cpp
@@ -66,7 +66,6 @@ std::locale::id my_facet::id;
 int main(int, char**)
 {
 {
-    globalMemCounter.reset();
     {
         std::locale loc;
         std::locale loc2(loc, new my_facet);

diff  --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp
index 9393da08964d..cf3477ff5544 100644
--- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp
+++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp
@@ -59,7 +59,6 @@ int h(int) {return 1;}
 
 int main(int, char**)
 {
-    globalMemCounter.reset();
     assert(globalMemCounter.checkOutstandingNewEq(0));
     {
     std::function<int(int)> f1 = A(1);

diff  --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp
index 7cb220d993af..5944f5900ee0 100644
--- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp
+++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp
@@ -62,7 +62,6 @@ struct LValueCallable {
 
 int main(int, char**)
 {
-    globalMemCounter.reset();
     assert(globalMemCounter.checkOutstandingNewEq(0));
     {
     std::function<int(int)> f = A();

diff  --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp
index 75471326b370..26178551edb3 100644
--- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp
+++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp
@@ -65,7 +65,6 @@ struct LValueCallable {
 
 int main(int, char**)
 {
-    globalMemCounter.reset();
     assert(globalMemCounter.checkOutstandingNewEq(0));
     {
     std::function<int(int)> f;

diff  --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp
index 05c52a1c2a28..d97b699ea96a 100644
--- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp
+++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp
@@ -49,7 +49,6 @@ int g2(int, int) { return 2; }
 int g3(int, int, int) { return 3; }
 
 int main(int, char**) {
-  globalMemCounter.reset();
   assert(globalMemCounter.checkOutstandingNewEq(0));
   {
     std::function<int(int)> f = A();

diff  --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp
index 1251e62f4bab..b756e7ecef92 100644
--- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp
+++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp
@@ -52,7 +52,6 @@ int g(int) {return 0;}
 
 int main(int, char**)
 {
-    globalMemCounter.reset();
     assert(globalMemCounter.checkOutstandingNewEq(0));
     {
     std::function<int(int)> f = A();

diff  --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp
index 264b0fe7ca4e..16d9f05622d3 100644
--- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp
+++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp
@@ -50,7 +50,6 @@ int g(int) {return 0;}
 
 int main(int, char**)
 {
-    globalMemCounter.reset();
     assert(globalMemCounter.checkOutstandingNewEq(0));
     {
     std::function<int(int)> f = A();

diff  --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp
index eedba02a9c26..f034eb71e4d7 100644
--- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp
+++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp
@@ -60,7 +60,6 @@ int g2(int, int) { return 2; }
 int g3(int, int, int) { return 3; }
 
 int main(int, char**) {
-  globalMemCounter.reset();
   assert(globalMemCounter.checkOutstandingNewEq(0));
   {
     std::function<int(int)> f1 = A(1);

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp
index e403ea6fc102..8dd984dcddee 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp
@@ -54,7 +54,6 @@ struct PrivateBase : private std::enable_shared_from_this<PrivateBase> {
 
 int main(int, char**)
 {
-    globalMemCounter.reset();
     {  // https://bugs.llvm.org/show_bug.cgi?id=18843
     std::shared_ptr<T const> t1(new T);
     std::shared_ptr<T const> t2(std::make_shared<T>());

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp
index 826862f66c74..4a5ae751bc40 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp
@@ -37,7 +37,6 @@ int A::count = 0;
 
 int main(int, char**)
 {
-    globalMemCounter.reset();
     A* ptr = new A;
     globalMemCounter.throw_after = 0;
     try

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp
index 6506890aa353..fd33ce9cb9ea 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp
@@ -37,7 +37,6 @@ int A::count = 0;
 
 int main(int, char**)
 {
-    globalMemCounter.reset();
     A* ptr = new A;
     assert(A::count == 1);
     globalMemCounter.throw_after = 0;


        


More information about the libcxx-commits mailing list