[libcxx-commits] [libcxx] [libcxxabi] [libc++] Fix noexcept behaviour of operator new helper functions (PR #74337)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jan 19 07:24:32 PST 2024
https://github.com/azhan92 updated https://github.com/llvm/llvm-project/pull/74337
>From 5041d441856cda19cf796e16a13b4e0049d33342 Mon Sep 17 00:00:00 2001
From: Alison Zhang <alisonzhang at ibm.com>
Date: Mon, 4 Dec 2023 11:35:20 -0500
Subject: [PATCH 1/5] remove noexcept
---
libcxx/src/new.cpp | 4 +--
libcxxabi/src/stdlib_new_delete.cpp | 4 +--
libcxxabi/test/test_memory_alloc.pass.cpp | 34 +++++++++++++++++++++++
3 files changed, 38 insertions(+), 4 deletions(-)
create mode 100644 libcxxabi/test/test_memory_alloc.pass.cpp
diff --git a/libcxx/src/new.cpp b/libcxx/src/new.cpp
index 033bba5c1fc95b6..cb8b4aae8d5f94b 100644
--- a/libcxx/src/new.cpp
+++ b/libcxx/src/new.cpp
@@ -20,7 +20,7 @@
// in this shared library, so that they can be overridden by programs
// that define non-weak copies of the functions.
-static void* operator_new_impl(std::size_t size) noexcept {
+static void* operator_new_impl(std::size_t size) {
if (size == 0)
size = 1;
void* p;
@@ -87,7 +87,7 @@ _LIBCPP_WEAK void operator delete[](void* ptr, size_t) noexcept { ::operator del
# if !defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION)
-static void* operator_new_aligned_impl(std::size_t size, std::align_val_t alignment) noexcept {
+static void* operator_new_aligned_impl(std::size_t size, std::align_val_t alignment) {
if (size == 0)
size = 1;
if (static_cast<size_t>(alignment) < sizeof(void*))
diff --git a/libcxxabi/src/stdlib_new_delete.cpp b/libcxxabi/src/stdlib_new_delete.cpp
index 6c9990f063dde66..f8a00ec5842566e 100644
--- a/libcxxabi/src/stdlib_new_delete.cpp
+++ b/libcxxabi/src/stdlib_new_delete.cpp
@@ -30,7 +30,7 @@
// in this shared library, so that they can be overridden by programs
// that define non-weak copies of the functions.
-static void* operator_new_impl(std::size_t size) noexcept {
+static void* operator_new_impl(std::size_t size) {
if (size == 0)
size = 1;
void* p;
@@ -107,7 +107,7 @@ void operator delete[](void* ptr, size_t) noexcept { ::operator delete[](ptr); }
#if !defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION)
-static void* operator_new_aligned_impl(std::size_t size, std::align_val_t alignment) noexcept {
+static void* operator_new_aligned_impl(std::size_t size, std::align_val_t alignment) {
if (size == 0)
size = 1;
if (static_cast<size_t>(alignment) < sizeof(void*))
diff --git a/libcxxabi/test/test_memory_alloc.pass.cpp b/libcxxabi/test/test_memory_alloc.pass.cpp
new file mode 100644
index 000000000000000..219b85b9afcafa6
--- /dev/null
+++ b/libcxxabi/test/test_memory_alloc.pass.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: no-exceptions
+
+#include <new>
+#include <cassert>
+#include <limits>
+
+int new_handler_called = 0;
+
+void my_new_handler() {
+ ++new_handler_called;
+ throw std::bad_alloc();
+}
+
+int main(int, char**) {
+ std::set_new_handler(my_new_handler);
+ try {
+ void* x = operator new[](std::numeric_limits<std::size_t>::max());
+ (void)x;
+ assert(false);
+ } catch (std::bad_alloc const&) {
+ assert(new_handler_called == 1);
+ } catch (...) {
+ assert(false);
+ }
+ return 0;
+}
>From 227d0ba122403e8773318eca47a05e7fc2a5421e Mon Sep 17 00:00:00 2001
From: Alison Zhang <alisonzhang at ibm.com>
Date: Fri, 12 Jan 2024 16:35:03 -0500
Subject: [PATCH 2/5] Update test cases
---
libcxxabi/test/test_memory_alloc1.pass.cpp | 42 +++++++++++++++++++
libcxxabi/test/test_memory_alloc2.pass.cpp | 42 +++++++++++++++++++
libcxxabi/test/test_memory_alloc3.pass.cpp | 42 +++++++++++++++++++
libcxxabi/test/test_memory_alloc4.pass.cpp | 42 +++++++++++++++++++
.../test/test_memory_alloc_nothrow1.pass.cpp | 42 +++++++++++++++++++
.../test/test_memory_alloc_nothrow2.pass.cpp | 42 +++++++++++++++++++
.../test/test_memory_alloc_nothrow3.pass.cpp | 42 +++++++++++++++++++
.../test/test_memory_alloc_nothrow4.pass.cpp | 42 +++++++++++++++++++
8 files changed, 336 insertions(+)
create mode 100644 libcxxabi/test/test_memory_alloc1.pass.cpp
create mode 100644 libcxxabi/test/test_memory_alloc2.pass.cpp
create mode 100644 libcxxabi/test/test_memory_alloc3.pass.cpp
create mode 100644 libcxxabi/test/test_memory_alloc4.pass.cpp
create mode 100644 libcxxabi/test/test_memory_alloc_nothrow1.pass.cpp
create mode 100644 libcxxabi/test/test_memory_alloc_nothrow2.pass.cpp
create mode 100644 libcxxabi/test/test_memory_alloc_nothrow3.pass.cpp
create mode 100644 libcxxabi/test/test_memory_alloc_nothrow4.pass.cpp
diff --git a/libcxxabi/test/test_memory_alloc1.pass.cpp b/libcxxabi/test/test_memory_alloc1.pass.cpp
new file mode 100644
index 000000000000000..aa202e04e8f39ab
--- /dev/null
+++ b/libcxxabi/test/test_memory_alloc1.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: no-exceptions
+#include <new>
+#include <cassert>
+#include <limits>
+#include <cstdlib>
+
+struct construction_key {};
+struct my_bad_alloc : std::bad_alloc {
+ my_bad_alloc(const my_bad_alloc &) : self(this) { std::abort(); }
+ my_bad_alloc(construction_key) : self(this) {}
+ const my_bad_alloc *const self;
+};
+
+int new_handler_called = 0;
+
+void my_new_handler() {
+ ++new_handler_called;
+ throw my_bad_alloc(construction_key{});
+}
+
+int main(int, char**) {
+ std::set_new_handler(my_new_handler);
+ try {
+ void* x = operator new(std::numeric_limits<std::size_t>::max());
+ (void)x;
+ assert(false);
+ } catch (my_bad_alloc const& e) {
+ assert(new_handler_called == 1);
+ assert(e.self == &e);
+ } catch (...) {
+ assert(false);
+ }
+ return 0;
+}
diff --git a/libcxxabi/test/test_memory_alloc2.pass.cpp b/libcxxabi/test/test_memory_alloc2.pass.cpp
new file mode 100644
index 000000000000000..1049d7d3a6387c6
--- /dev/null
+++ b/libcxxabi/test/test_memory_alloc2.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: no-exceptions
+#include <new>
+#include <cassert>
+#include <limits>
+#include <cstdlib>
+
+struct construction_key {};
+struct my_bad_alloc : std::bad_alloc {
+ my_bad_alloc(const my_bad_alloc &) : self(this) { std::abort(); }
+ my_bad_alloc(construction_key) : self(this) {}
+ const my_bad_alloc *const self;
+};
+
+int new_handler_called = 0;
+
+void my_new_handler() {
+ ++new_handler_called;
+ throw my_bad_alloc(construction_key{});
+}
+
+int main(int, char**) {
+ std::set_new_handler(my_new_handler);
+ try {
+ void* x = operator new[](std::numeric_limits<std::size_t>::max());
+ (void)x;
+ assert(false);
+ } catch (my_bad_alloc const& e) {
+ assert(new_handler_called == 1);
+ assert(e.self == &e);
+ } catch (...) {
+ assert(false);
+ }
+ return 0;
+}
diff --git a/libcxxabi/test/test_memory_alloc3.pass.cpp b/libcxxabi/test/test_memory_alloc3.pass.cpp
new file mode 100644
index 000000000000000..fee1f15bd6cda66
--- /dev/null
+++ b/libcxxabi/test/test_memory_alloc3.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: no-exceptions
+#include <new>
+#include <cassert>
+#include <limits>
+#include <cstdlib>
+
+struct construction_key {};
+struct my_bad_alloc : std::bad_alloc {
+ my_bad_alloc(const my_bad_alloc &) : self(this) { std::abort(); }
+ my_bad_alloc(construction_key) : self(this) {}
+ const my_bad_alloc *const self;
+};
+
+int new_handler_called = 0;
+
+void my_new_handler() {
+ ++new_handler_called;
+ throw my_bad_alloc(construction_key{});
+}
+
+int main(int, char**) {
+ std::set_new_handler(my_new_handler);
+ try {
+ void* x = operator new(std::numeric_limits<std::size_t>::max(), static_cast<std::align_val_t>(32));
+ (void)x;
+ assert(false);
+ } catch (my_bad_alloc const& e) {
+ assert(new_handler_called == 1);
+ assert(e.self == &e);
+ } catch (...) {
+ assert(false);
+ }
+ return 0;
+}
diff --git a/libcxxabi/test/test_memory_alloc4.pass.cpp b/libcxxabi/test/test_memory_alloc4.pass.cpp
new file mode 100644
index 000000000000000..1a152ef6ed56bb4
--- /dev/null
+++ b/libcxxabi/test/test_memory_alloc4.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: no-exceptions
+#include <new>
+#include <cassert>
+#include <limits>
+#include <cstdlib>
+
+struct construction_key {};
+struct my_bad_alloc : std::bad_alloc {
+ my_bad_alloc(const my_bad_alloc &) : self(this) { std::abort(); }
+ my_bad_alloc(construction_key) : self(this) {}
+ const my_bad_alloc *const self;
+};
+
+int new_handler_called = 0;
+
+void my_new_handler() {
+ ++new_handler_called;
+ throw my_bad_alloc(construction_key{});
+}
+
+int main(int, char**) {
+ std::set_new_handler(my_new_handler);
+ try {
+ void* x = operator new[](std::numeric_limits<std::size_t>::max(), static_cast<std::align_val_t>(32));
+ (void)x;
+ assert(false);
+ } catch (my_bad_alloc const& e) {
+ assert(new_handler_called == 1);
+ assert(e.self == &e);
+ } catch (...) {
+ assert(false);
+ }
+ return 0;
+}
diff --git a/libcxxabi/test/test_memory_alloc_nothrow1.pass.cpp b/libcxxabi/test/test_memory_alloc_nothrow1.pass.cpp
new file mode 100644
index 000000000000000..49ceefe56a27b98
--- /dev/null
+++ b/libcxxabi/test/test_memory_alloc_nothrow1.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: no-exceptions
+#include <new>
+#include <cassert>
+#include <limits>
+#include <cstdlib>
+
+struct construction_key {};
+struct my_bad_alloc : std::bad_alloc {
+ my_bad_alloc(const my_bad_alloc &) : self(this) { std::abort(); }
+ my_bad_alloc(construction_key) : self(this) {}
+ const my_bad_alloc *const self;
+};
+
+int new_handler_called = 0;
+
+void my_new_handler() {
+ ++new_handler_called;
+ throw my_bad_alloc(construction_key{});
+}
+
+int main(int, char**) {
+ std::set_new_handler(my_new_handler);
+ try {
+ void* x = operator new(std::numeric_limits<std::size_t>::max(), std::nothrow);
+ (void)x;
+ assert(x == NULL);
+ } catch (my_bad_alloc const& e) {
+ assert(new_handler_called == 1);
+ assert(e.self == &e);
+ } catch (...) {
+ assert(false);
+ }
+ return 0;
+}
diff --git a/libcxxabi/test/test_memory_alloc_nothrow2.pass.cpp b/libcxxabi/test/test_memory_alloc_nothrow2.pass.cpp
new file mode 100644
index 000000000000000..deff9f0a1b9f425
--- /dev/null
+++ b/libcxxabi/test/test_memory_alloc_nothrow2.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: no-exceptions
+#include <new>
+#include <cassert>
+#include <limits>
+#include <cstdlib>
+
+struct construction_key {};
+struct my_bad_alloc : std::bad_alloc {
+ my_bad_alloc(const my_bad_alloc &) : self(this) { std::abort(); }
+ my_bad_alloc(construction_key) : self(this) {}
+ const my_bad_alloc *const self;
+};
+
+int new_handler_called = 0;
+
+void my_new_handler() {
+ ++new_handler_called;
+ throw my_bad_alloc(construction_key{});
+}
+
+int main(int, char**) {
+ std::set_new_handler(my_new_handler);
+ try {
+ void* x = operator new[](std::numeric_limits<std::size_t>::max(), std::nothrow);
+ (void)x;
+ assert(x == NULL);
+ } catch (my_bad_alloc const& e) {
+ assert(new_handler_called == 1);
+ assert(e.self == &e);
+ } catch (...) {
+ assert(false);
+ }
+ return 0;
+}
diff --git a/libcxxabi/test/test_memory_alloc_nothrow3.pass.cpp b/libcxxabi/test/test_memory_alloc_nothrow3.pass.cpp
new file mode 100644
index 000000000000000..62072254dd31a53
--- /dev/null
+++ b/libcxxabi/test/test_memory_alloc_nothrow3.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: no-exceptions
+#include <new>
+#include <cassert>
+#include <limits>
+#include <cstdlib>
+
+struct construction_key {};
+struct my_bad_alloc : std::bad_alloc {
+ my_bad_alloc(const my_bad_alloc &) : self(this) { std::abort(); }
+ my_bad_alloc(construction_key) : self(this) {}
+ const my_bad_alloc *const self;
+};
+
+int new_handler_called = 0;
+
+void my_new_handler() {
+ ++new_handler_called;
+ throw my_bad_alloc(construction_key{});
+}
+
+int main(int, char**) {
+ std::set_new_handler(my_new_handler);
+ try {
+ void* x = operator new(std::numeric_limits<std::size_t>::max(), static_cast<std::align_val_t>(32), std::nothrow);
+ (void)x;
+ assert(x == NULL);
+ } catch (my_bad_alloc const& e) {
+ assert(new_handler_called == 1);
+ assert(e.self == &e);
+ } catch (...) {
+ assert(false);
+ }
+ return 0;
+}
diff --git a/libcxxabi/test/test_memory_alloc_nothrow4.pass.cpp b/libcxxabi/test/test_memory_alloc_nothrow4.pass.cpp
new file mode 100644
index 000000000000000..b6d183e846a4eae
--- /dev/null
+++ b/libcxxabi/test/test_memory_alloc_nothrow4.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: no-exceptions
+#include <new>
+#include <cassert>
+#include <limits>
+#include <cstdlib>
+
+struct construction_key {};
+struct my_bad_alloc : std::bad_alloc {
+ my_bad_alloc(const my_bad_alloc &) : self(this) { std::abort(); }
+ my_bad_alloc(construction_key) : self(this) {}
+ const my_bad_alloc *const self;
+};
+
+int new_handler_called = 0;
+
+void my_new_handler() {
+ ++new_handler_called;
+ throw my_bad_alloc(construction_key{});
+}
+
+int main(int, char**) {
+ std::set_new_handler(my_new_handler);
+ try {
+ void* x = operator new[](std::numeric_limits<std::size_t>::max(), static_cast<std::align_val_t>(32), std::nothrow);
+ (void)x;
+ assert(x == NULL);
+ } catch (my_bad_alloc const& e) {
+ assert(new_handler_called == 1);
+ assert(e.self == &e);
+ } catch (...) {
+ assert(false);
+ }
+ return 0;
+}
>From 9721224185fb41874b3fb5b3237ae6b827638e4f Mon Sep 17 00:00:00 2001
From: Alison Zhang <alisonzhang at ibm.com>
Date: Fri, 12 Jan 2024 16:54:53 -0500
Subject: [PATCH 3/5] Reformat
---
libcxxabi/test/test_memory_alloc1.pass.cpp | 4 ++--
libcxxabi/test/test_memory_alloc2.pass.cpp | 4 ++--
libcxxabi/test/test_memory_alloc3.pass.cpp | 4 ++--
libcxxabi/test/test_memory_alloc4.pass.cpp | 4 ++--
libcxxabi/test/test_memory_alloc_nothrow1.pass.cpp | 4 ++--
libcxxabi/test/test_memory_alloc_nothrow2.pass.cpp | 4 ++--
libcxxabi/test/test_memory_alloc_nothrow3.pass.cpp | 4 ++--
libcxxabi/test/test_memory_alloc_nothrow4.pass.cpp | 4 ++--
8 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/libcxxabi/test/test_memory_alloc1.pass.cpp b/libcxxabi/test/test_memory_alloc1.pass.cpp
index aa202e04e8f39ab..3b3a2aa418b3620 100644
--- a/libcxxabi/test/test_memory_alloc1.pass.cpp
+++ b/libcxxabi/test/test_memory_alloc1.pass.cpp
@@ -14,9 +14,9 @@
struct construction_key {};
struct my_bad_alloc : std::bad_alloc {
- my_bad_alloc(const my_bad_alloc &) : self(this) { std::abort(); }
+ my_bad_alloc(const my_bad_alloc&) : self(this) { std::abort(); }
my_bad_alloc(construction_key) : self(this) {}
- const my_bad_alloc *const self;
+ const my_bad_alloc* const self;
};
int new_handler_called = 0;
diff --git a/libcxxabi/test/test_memory_alloc2.pass.cpp b/libcxxabi/test/test_memory_alloc2.pass.cpp
index 1049d7d3a6387c6..88da9658c827dbd 100644
--- a/libcxxabi/test/test_memory_alloc2.pass.cpp
+++ b/libcxxabi/test/test_memory_alloc2.pass.cpp
@@ -14,9 +14,9 @@
struct construction_key {};
struct my_bad_alloc : std::bad_alloc {
- my_bad_alloc(const my_bad_alloc &) : self(this) { std::abort(); }
+ my_bad_alloc(const my_bad_alloc&) : self(this) { std::abort(); }
my_bad_alloc(construction_key) : self(this) {}
- const my_bad_alloc *const self;
+ const my_bad_alloc* const self;
};
int new_handler_called = 0;
diff --git a/libcxxabi/test/test_memory_alloc3.pass.cpp b/libcxxabi/test/test_memory_alloc3.pass.cpp
index fee1f15bd6cda66..ba454471e04682b 100644
--- a/libcxxabi/test/test_memory_alloc3.pass.cpp
+++ b/libcxxabi/test/test_memory_alloc3.pass.cpp
@@ -14,9 +14,9 @@
struct construction_key {};
struct my_bad_alloc : std::bad_alloc {
- my_bad_alloc(const my_bad_alloc &) : self(this) { std::abort(); }
+ my_bad_alloc(const my_bad_alloc&) : self(this) { std::abort(); }
my_bad_alloc(construction_key) : self(this) {}
- const my_bad_alloc *const self;
+ const my_bad_alloc* const self;
};
int new_handler_called = 0;
diff --git a/libcxxabi/test/test_memory_alloc4.pass.cpp b/libcxxabi/test/test_memory_alloc4.pass.cpp
index 1a152ef6ed56bb4..ad64596db0cb748 100644
--- a/libcxxabi/test/test_memory_alloc4.pass.cpp
+++ b/libcxxabi/test/test_memory_alloc4.pass.cpp
@@ -14,9 +14,9 @@
struct construction_key {};
struct my_bad_alloc : std::bad_alloc {
- my_bad_alloc(const my_bad_alloc &) : self(this) { std::abort(); }
+ my_bad_alloc(const my_bad_alloc&) : self(this) { std::abort(); }
my_bad_alloc(construction_key) : self(this) {}
- const my_bad_alloc *const self;
+ const my_bad_alloc* const self;
};
int new_handler_called = 0;
diff --git a/libcxxabi/test/test_memory_alloc_nothrow1.pass.cpp b/libcxxabi/test/test_memory_alloc_nothrow1.pass.cpp
index 49ceefe56a27b98..51992f0b8d3cd4e 100644
--- a/libcxxabi/test/test_memory_alloc_nothrow1.pass.cpp
+++ b/libcxxabi/test/test_memory_alloc_nothrow1.pass.cpp
@@ -14,9 +14,9 @@
struct construction_key {};
struct my_bad_alloc : std::bad_alloc {
- my_bad_alloc(const my_bad_alloc &) : self(this) { std::abort(); }
+ my_bad_alloc(const my_bad_alloc&) : self(this) { std::abort(); }
my_bad_alloc(construction_key) : self(this) {}
- const my_bad_alloc *const self;
+ const my_bad_alloc* const self;
};
int new_handler_called = 0;
diff --git a/libcxxabi/test/test_memory_alloc_nothrow2.pass.cpp b/libcxxabi/test/test_memory_alloc_nothrow2.pass.cpp
index deff9f0a1b9f425..6dda87d09065d40 100644
--- a/libcxxabi/test/test_memory_alloc_nothrow2.pass.cpp
+++ b/libcxxabi/test/test_memory_alloc_nothrow2.pass.cpp
@@ -14,9 +14,9 @@
struct construction_key {};
struct my_bad_alloc : std::bad_alloc {
- my_bad_alloc(const my_bad_alloc &) : self(this) { std::abort(); }
+ my_bad_alloc(const my_bad_alloc&) : self(this) { std::abort(); }
my_bad_alloc(construction_key) : self(this) {}
- const my_bad_alloc *const self;
+ const my_bad_alloc* const self;
};
int new_handler_called = 0;
diff --git a/libcxxabi/test/test_memory_alloc_nothrow3.pass.cpp b/libcxxabi/test/test_memory_alloc_nothrow3.pass.cpp
index 62072254dd31a53..ce52a1e3c2200d6 100644
--- a/libcxxabi/test/test_memory_alloc_nothrow3.pass.cpp
+++ b/libcxxabi/test/test_memory_alloc_nothrow3.pass.cpp
@@ -14,9 +14,9 @@
struct construction_key {};
struct my_bad_alloc : std::bad_alloc {
- my_bad_alloc(const my_bad_alloc &) : self(this) { std::abort(); }
+ my_bad_alloc(const my_bad_alloc&) : self(this) { std::abort(); }
my_bad_alloc(construction_key) : self(this) {}
- const my_bad_alloc *const self;
+ const my_bad_alloc* const self;
};
int new_handler_called = 0;
diff --git a/libcxxabi/test/test_memory_alloc_nothrow4.pass.cpp b/libcxxabi/test/test_memory_alloc_nothrow4.pass.cpp
index b6d183e846a4eae..8f4f66f1d16f642 100644
--- a/libcxxabi/test/test_memory_alloc_nothrow4.pass.cpp
+++ b/libcxxabi/test/test_memory_alloc_nothrow4.pass.cpp
@@ -14,9 +14,9 @@
struct construction_key {};
struct my_bad_alloc : std::bad_alloc {
- my_bad_alloc(const my_bad_alloc &) : self(this) { std::abort(); }
+ my_bad_alloc(const my_bad_alloc&) : self(this) { std::abort(); }
my_bad_alloc(construction_key) : self(this) {}
- const my_bad_alloc *const self;
+ const my_bad_alloc* const self;
};
int new_handler_called = 0;
>From af527c4f5b040a2e2c4ee7b633bd073bb4f9f584 Mon Sep 17 00:00:00 2001
From: Alison Zhang <alisonzhang at ibm.com>
Date: Mon, 15 Jan 2024 14:40:27 -0500
Subject: [PATCH 4/5] Update construction pattern
---
libcxxabi/test/test_memory_alloc1.pass.cpp | 2 +-
libcxxabi/test/test_memory_alloc2.pass.cpp | 2 +-
libcxxabi/test/test_memory_alloc3.pass.cpp | 2 +-
libcxxabi/test/test_memory_alloc4.pass.cpp | 2 +-
libcxxabi/test/test_memory_alloc_nothrow1.pass.cpp | 2 +-
libcxxabi/test/test_memory_alloc_nothrow2.pass.cpp | 2 +-
libcxxabi/test/test_memory_alloc_nothrow3.pass.cpp | 2 +-
libcxxabi/test/test_memory_alloc_nothrow4.pass.cpp | 2 +-
8 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/libcxxabi/test/test_memory_alloc1.pass.cpp b/libcxxabi/test/test_memory_alloc1.pass.cpp
index 3b3a2aa418b3620..2730bb669034a12 100644
--- a/libcxxabi/test/test_memory_alloc1.pass.cpp
+++ b/libcxxabi/test/test_memory_alloc1.pass.cpp
@@ -23,7 +23,7 @@ int new_handler_called = 0;
void my_new_handler() {
++new_handler_called;
- throw my_bad_alloc(construction_key{});
+ throw my_bad_alloc(construction_key());
}
int main(int, char**) {
diff --git a/libcxxabi/test/test_memory_alloc2.pass.cpp b/libcxxabi/test/test_memory_alloc2.pass.cpp
index 88da9658c827dbd..9c1ca322844c110 100644
--- a/libcxxabi/test/test_memory_alloc2.pass.cpp
+++ b/libcxxabi/test/test_memory_alloc2.pass.cpp
@@ -23,7 +23,7 @@ int new_handler_called = 0;
void my_new_handler() {
++new_handler_called;
- throw my_bad_alloc(construction_key{});
+ throw my_bad_alloc(construction_key());
}
int main(int, char**) {
diff --git a/libcxxabi/test/test_memory_alloc3.pass.cpp b/libcxxabi/test/test_memory_alloc3.pass.cpp
index ba454471e04682b..2ba6d96d18652e2 100644
--- a/libcxxabi/test/test_memory_alloc3.pass.cpp
+++ b/libcxxabi/test/test_memory_alloc3.pass.cpp
@@ -23,7 +23,7 @@ int new_handler_called = 0;
void my_new_handler() {
++new_handler_called;
- throw my_bad_alloc(construction_key{});
+ throw my_bad_alloc(construction_key());
}
int main(int, char**) {
diff --git a/libcxxabi/test/test_memory_alloc4.pass.cpp b/libcxxabi/test/test_memory_alloc4.pass.cpp
index ad64596db0cb748..02d02eeea3b677c 100644
--- a/libcxxabi/test/test_memory_alloc4.pass.cpp
+++ b/libcxxabi/test/test_memory_alloc4.pass.cpp
@@ -23,7 +23,7 @@ int new_handler_called = 0;
void my_new_handler() {
++new_handler_called;
- throw my_bad_alloc(construction_key{});
+ throw my_bad_alloc(construction_key());
}
int main(int, char**) {
diff --git a/libcxxabi/test/test_memory_alloc_nothrow1.pass.cpp b/libcxxabi/test/test_memory_alloc_nothrow1.pass.cpp
index 51992f0b8d3cd4e..4d88f6582e46f64 100644
--- a/libcxxabi/test/test_memory_alloc_nothrow1.pass.cpp
+++ b/libcxxabi/test/test_memory_alloc_nothrow1.pass.cpp
@@ -23,7 +23,7 @@ int new_handler_called = 0;
void my_new_handler() {
++new_handler_called;
- throw my_bad_alloc(construction_key{});
+ throw my_bad_alloc(construction_key());
}
int main(int, char**) {
diff --git a/libcxxabi/test/test_memory_alloc_nothrow2.pass.cpp b/libcxxabi/test/test_memory_alloc_nothrow2.pass.cpp
index 6dda87d09065d40..16b966e17711b2c 100644
--- a/libcxxabi/test/test_memory_alloc_nothrow2.pass.cpp
+++ b/libcxxabi/test/test_memory_alloc_nothrow2.pass.cpp
@@ -23,7 +23,7 @@ int new_handler_called = 0;
void my_new_handler() {
++new_handler_called;
- throw my_bad_alloc(construction_key{});
+ throw my_bad_alloc(construction_key());
}
int main(int, char**) {
diff --git a/libcxxabi/test/test_memory_alloc_nothrow3.pass.cpp b/libcxxabi/test/test_memory_alloc_nothrow3.pass.cpp
index ce52a1e3c2200d6..b2dbdd46f786344 100644
--- a/libcxxabi/test/test_memory_alloc_nothrow3.pass.cpp
+++ b/libcxxabi/test/test_memory_alloc_nothrow3.pass.cpp
@@ -23,7 +23,7 @@ int new_handler_called = 0;
void my_new_handler() {
++new_handler_called;
- throw my_bad_alloc(construction_key{});
+ throw my_bad_alloc(construction_key());
}
int main(int, char**) {
diff --git a/libcxxabi/test/test_memory_alloc_nothrow4.pass.cpp b/libcxxabi/test/test_memory_alloc_nothrow4.pass.cpp
index 8f4f66f1d16f642..4496f3a61da558a 100644
--- a/libcxxabi/test/test_memory_alloc_nothrow4.pass.cpp
+++ b/libcxxabi/test/test_memory_alloc_nothrow4.pass.cpp
@@ -23,7 +23,7 @@ int new_handler_called = 0;
void my_new_handler() {
++new_handler_called;
- throw my_bad_alloc(construction_key{});
+ throw my_bad_alloc(construction_key());
}
int main(int, char**) {
>From 5aac3b99810bca33db36f25f2575cabff8fd6365 Mon Sep 17 00:00:00 2001
From: Alison Zhang <alisonzhang at ibm.com>
Date: Fri, 19 Jan 2024 10:24:14 -0500
Subject: [PATCH 5/5] Move test files
---
.../new.delete.array/new.size.except.pass.cpp | 2 ++
.../new.size_align.except.pass.cpp | 2 ++
.../new.size_align_nothrow.except.pass.cpp | 2 ++
.../new.size_nothrow.except.pass.cpp | 2 ++
.../new.size.except.pass.cpp | 2 ++
.../new.size_align.except.pass.cpp | 2 ++
.../new.size_align_nothrow.except.pass.cpp | 2 ++
.../new.size_nothrow.except.pass.cpp | 2 ++
libcxxabi/test/test_memory_alloc.pass.cpp | 34 -------------------
9 files changed, 16 insertions(+), 34 deletions(-)
rename libcxxabi/test/test_memory_alloc2.pass.cpp => libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size.except.pass.cpp (96%)
rename libcxxabi/test/test_memory_alloc4.pass.cpp => libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size_align.except.pass.cpp (96%)
rename libcxxabi/test/test_memory_alloc_nothrow4.pass.cpp => libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size_align_nothrow.except.pass.cpp (96%)
rename libcxxabi/test/test_memory_alloc_nothrow2.pass.cpp => libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size_nothrow.except.pass.cpp (96%)
rename libcxxabi/test/test_memory_alloc1.pass.cpp => libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size.except.pass.cpp (96%)
rename libcxxabi/test/test_memory_alloc3.pass.cpp => libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size_align.except.pass.cpp (96%)
rename libcxxabi/test/test_memory_alloc_nothrow3.pass.cpp => libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size_align_nothrow.except.pass.cpp (96%)
rename libcxxabi/test/test_memory_alloc_nothrow1.pass.cpp => libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size_nothrow.except.pass.cpp (96%)
delete mode 100644 libcxxabi/test/test_memory_alloc.pass.cpp
diff --git a/libcxxabi/test/test_memory_alloc2.pass.cpp b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size.except.pass.cpp
similarity index 96%
rename from libcxxabi/test/test_memory_alloc2.pass.cpp
rename to libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size.except.pass.cpp
index 9c1ca322844c110..6a2b098c1b5738a 100644
--- a/libcxxabi/test/test_memory_alloc2.pass.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size.except.pass.cpp
@@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: no-exceptions
+// UNSUPPORTED: sanitizer-new-delete
+
#include <new>
#include <cassert>
#include <limits>
diff --git a/libcxxabi/test/test_memory_alloc4.pass.cpp b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size_align.except.pass.cpp
similarity index 96%
rename from libcxxabi/test/test_memory_alloc4.pass.cpp
rename to libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size_align.except.pass.cpp
index 02d02eeea3b677c..cde7dc53be5bde5 100644
--- a/libcxxabi/test/test_memory_alloc4.pass.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size_align.except.pass.cpp
@@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: no-exceptions
+// UNSUPPORTED: sanitizer-new-delete
+
#include <new>
#include <cassert>
#include <limits>
diff --git a/libcxxabi/test/test_memory_alloc_nothrow4.pass.cpp b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size_align_nothrow.except.pass.cpp
similarity index 96%
rename from libcxxabi/test/test_memory_alloc_nothrow4.pass.cpp
rename to libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size_align_nothrow.except.pass.cpp
index 4496f3a61da558a..251ba0f495991fd 100644
--- a/libcxxabi/test/test_memory_alloc_nothrow4.pass.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size_align_nothrow.except.pass.cpp
@@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: no-exceptions
+// UNSUPPORTED: sanitizer-new-delete
+
#include <new>
#include <cassert>
#include <limits>
diff --git a/libcxxabi/test/test_memory_alloc_nothrow2.pass.cpp b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size_nothrow.except.pass.cpp
similarity index 96%
rename from libcxxabi/test/test_memory_alloc_nothrow2.pass.cpp
rename to libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size_nothrow.except.pass.cpp
index 16b966e17711b2c..a68a980bb4f7a90 100644
--- a/libcxxabi/test/test_memory_alloc_nothrow2.pass.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new.size_nothrow.except.pass.cpp
@@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: no-exceptions
+// UNSUPPORTED: sanitizer-new-delete
+
#include <new>
#include <cassert>
#include <limits>
diff --git a/libcxxabi/test/test_memory_alloc1.pass.cpp b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size.except.pass.cpp
similarity index 96%
rename from libcxxabi/test/test_memory_alloc1.pass.cpp
rename to libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size.except.pass.cpp
index 2730bb669034a12..6a515555e6dbd67 100644
--- a/libcxxabi/test/test_memory_alloc1.pass.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size.except.pass.cpp
@@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: no-exceptions
+// UNSUPPORTED: sanitizer-new-delete
+
#include <new>
#include <cassert>
#include <limits>
diff --git a/libcxxabi/test/test_memory_alloc3.pass.cpp b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size_align.except.pass.cpp
similarity index 96%
rename from libcxxabi/test/test_memory_alloc3.pass.cpp
rename to libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size_align.except.pass.cpp
index 2ba6d96d18652e2..cb83fb26ab1e6ce 100644
--- a/libcxxabi/test/test_memory_alloc3.pass.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size_align.except.pass.cpp
@@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: no-exceptions
+// UNSUPPORTED: sanitizer-new-delete
+
#include <new>
#include <cassert>
#include <limits>
diff --git a/libcxxabi/test/test_memory_alloc_nothrow3.pass.cpp b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size_align_nothrow.except.pass.cpp
similarity index 96%
rename from libcxxabi/test/test_memory_alloc_nothrow3.pass.cpp
rename to libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size_align_nothrow.except.pass.cpp
index b2dbdd46f786344..d95e78e24e1a9bb 100644
--- a/libcxxabi/test/test_memory_alloc_nothrow3.pass.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size_align_nothrow.except.pass.cpp
@@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: no-exceptions
+// UNSUPPORTED: sanitizer-new-delete
+
#include <new>
#include <cassert>
#include <limits>
diff --git a/libcxxabi/test/test_memory_alloc_nothrow1.pass.cpp b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size_nothrow.except.pass.cpp
similarity index 96%
rename from libcxxabi/test/test_memory_alloc_nothrow1.pass.cpp
rename to libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size_nothrow.except.pass.cpp
index 4d88f6582e46f64..db9a90709b50548 100644
--- a/libcxxabi/test/test_memory_alloc_nothrow1.pass.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.size_nothrow.except.pass.cpp
@@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: no-exceptions
+// UNSUPPORTED: sanitizer-new-delete
+
#include <new>
#include <cassert>
#include <limits>
diff --git a/libcxxabi/test/test_memory_alloc.pass.cpp b/libcxxabi/test/test_memory_alloc.pass.cpp
deleted file mode 100644
index 219b85b9afcafa6..000000000000000
--- a/libcxxabi/test/test_memory_alloc.pass.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// UNSUPPORTED: no-exceptions
-
-#include <new>
-#include <cassert>
-#include <limits>
-
-int new_handler_called = 0;
-
-void my_new_handler() {
- ++new_handler_called;
- throw std::bad_alloc();
-}
-
-int main(int, char**) {
- std::set_new_handler(my_new_handler);
- try {
- void* x = operator new[](std::numeric_limits<std::size_t>::max());
- (void)x;
- assert(false);
- } catch (std::bad_alloc const&) {
- assert(new_handler_called == 1);
- } catch (...) {
- assert(false);
- }
- return 0;
-}
More information about the libcxx-commits
mailing list