summaryrefslogtreecommitdiff
path: root/test/std/language.support/support.dynamic
diff options
context:
space:
mode:
Diffstat (limited to 'test/std/language.support/support.dynamic')
-rw-r--r--test/std/language.support/support.dynamic/alloc.errors/bad.alloc/bad_alloc.pass.cpp27
-rw-r--r--test/std/language.support/support.dynamic/alloc.errors/new.badlength/bad_array_length.pass.cpp29
-rw-r--r--test/std/language.support/support.dynamic/alloc.errors/new.badlength/bad_array_new_length.pass.cpp27
-rw-r--r--test/std/language.support/support.dynamic/alloc.errors/new.handler/new_handler.pass.cpp19
-rw-r--r--test/std/language.support/support.dynamic/alloc.errors/nothing_to_do.pass.cpp12
-rw-r--r--test/std/language.support/support.dynamic/alloc.errors/set.new.handler/get_new_handler.pass.cpp25
-rw-r--r--test/std/language.support/support.dynamic/alloc.errors/set.new.handler/set_new_handler.pass.cpp22
-rw-r--r--test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array.pass.cpp57
-rw-r--r--test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow.pass.cpp54
-rw-r--r--test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow_replace.pass.cpp51
-rw-r--r--test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_replace.pass.cpp51
-rw-r--r--test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array11.pass.cpp68
-rw-r--r--test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array14.pass.cpp73
-rw-r--r--test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array_calls_unsized_delete_array.pass.cpp56
-rw-r--r--test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array_fsizeddeallocation.sh.cpp80
-rw-r--r--test/std/language.support/support.dynamic/new.delete/new.delete.dataraces/not_testable.pass.cpp12
-rw-r--r--test/std/language.support/support.dynamic/new.delete/new.delete.placement/new.pass.cpp30
-rw-r--r--test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_array.pass.cpp30
-rw-r--r--test/std/language.support/support.dynamic/new.delete/new.delete.single/new.pass.cpp57
-rw-r--r--test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow.pass.cpp54
-rw-r--r--test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow_replace.pass.cpp51
-rw-r--r--test/std/language.support/support.dynamic/new.delete/new.delete.single/new_replace.pass.cpp51
-rw-r--r--test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete11.pass.cpp56
-rw-r--r--test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete14.pass.cpp62
-rw-r--r--test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete_calls_unsized_delete.pass.cpp45
-rw-r--r--test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete_fsizeddeallocation.sh.cpp69
-rw-r--r--test/std/language.support/support.dynamic/new.delete/nothing_to_do.pass.cpp12
-rw-r--r--test/std/language.support/support.dynamic/version.pass.cpp20
28 files changed, 1200 insertions, 0 deletions
diff --git a/test/std/language.support/support.dynamic/alloc.errors/bad.alloc/bad_alloc.pass.cpp b/test/std/language.support/support.dynamic/alloc.errors/bad.alloc/bad_alloc.pass.cpp
new file mode 100644
index 0000000000000..cf8d4af93802f
--- /dev/null
+++ b/test/std/language.support/support.dynamic/alloc.errors/bad.alloc/bad_alloc.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test bad_alloc
+
+#include <new>
+#include <type_traits>
+#include <cassert>
+
+int main()
+{
+ static_assert((std::is_base_of<std::exception, std::bad_alloc>::value),
+ "std::is_base_of<std::exception, std::bad_alloc>::value");
+ static_assert(std::is_polymorphic<std::bad_alloc>::value,
+ "std::is_polymorphic<std::bad_alloc>::value");
+ std::bad_alloc b;
+ std::bad_alloc b2 = b;
+ b2 = b;
+ const char* w = b2.what();
+ assert(w);
+}
diff --git a/test/std/language.support/support.dynamic/alloc.errors/new.badlength/bad_array_length.pass.cpp b/test/std/language.support/support.dynamic/alloc.errors/new.badlength/bad_array_length.pass.cpp
new file mode 100644
index 0000000000000..7de5033045566
--- /dev/null
+++ b/test/std/language.support/support.dynamic/alloc.errors/new.badlength/bad_array_length.pass.cpp
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test bad_array_length
+
+#include <new>
+#include <type_traits>
+#include <cassert>
+
+int main()
+{
+#if __LIBCPP_STD_VER > 11
+ static_assert((std::is_base_of<std::bad_alloc, std::bad_array_length>::value),
+ "std::is_base_of<std::bad_alloc, std::bad_array_length>::value");
+ static_assert(std::is_polymorphic<std::bad_array_length>::value,
+ "std::is_polymorphic<std::bad_array_length>::value");
+ std::bad_array_length b;
+ std::bad_array_length b2 = b;
+ b2 = b;
+ const char* w = b2.what();
+ assert(w);
+#endif
+}
diff --git a/test/std/language.support/support.dynamic/alloc.errors/new.badlength/bad_array_new_length.pass.cpp b/test/std/language.support/support.dynamic/alloc.errors/new.badlength/bad_array_new_length.pass.cpp
new file mode 100644
index 0000000000000..50521c0005a5f
--- /dev/null
+++ b/test/std/language.support/support.dynamic/alloc.errors/new.badlength/bad_array_new_length.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test bad_array_new_length
+
+#include <new>
+#include <type_traits>
+#include <cassert>
+
+int main()
+{
+ static_assert((std::is_base_of<std::bad_alloc, std::bad_array_new_length>::value),
+ "std::is_base_of<std::bad_alloc, std::bad_array_new_length>::value");
+ static_assert(std::is_polymorphic<std::bad_array_new_length>::value,
+ "std::is_polymorphic<std::bad_array_new_length>::value");
+ std::bad_array_new_length b;
+ std::bad_array_new_length b2 = b;
+ b2 = b;
+ const char* w = b2.what();
+ assert(w);
+}
diff --git a/test/std/language.support/support.dynamic/alloc.errors/new.handler/new_handler.pass.cpp b/test/std/language.support/support.dynamic/alloc.errors/new.handler/new_handler.pass.cpp
new file mode 100644
index 0000000000000..6b799a3e83d89
--- /dev/null
+++ b/test/std/language.support/support.dynamic/alloc.errors/new.handler/new_handler.pass.cpp
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test new_handler
+
+#include <new>
+
+void f() {}
+
+int main()
+{
+ std::new_handler p = f;
+}
diff --git a/test/std/language.support/support.dynamic/alloc.errors/nothing_to_do.pass.cpp b/test/std/language.support/support.dynamic/alloc.errors/nothing_to_do.pass.cpp
new file mode 100644
index 0000000000000..b58f5c55b643a
--- /dev/null
+++ b/test/std/language.support/support.dynamic/alloc.errors/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/test/std/language.support/support.dynamic/alloc.errors/set.new.handler/get_new_handler.pass.cpp b/test/std/language.support/support.dynamic/alloc.errors/set.new.handler/get_new_handler.pass.cpp
new file mode 100644
index 0000000000000..55a3edabfed8a
--- /dev/null
+++ b/test/std/language.support/support.dynamic/alloc.errors/set.new.handler/get_new_handler.pass.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test get_new_handler
+
+#include <new>
+#include <cassert>
+
+void f1() {}
+void f2() {}
+
+int main()
+{
+ assert(std::get_new_handler() == 0);
+ std::set_new_handler(f1);
+ assert(std::get_new_handler() == f1);
+ std::set_new_handler(f2);
+ assert(std::get_new_handler() == f2);
+}
diff --git a/test/std/language.support/support.dynamic/alloc.errors/set.new.handler/set_new_handler.pass.cpp b/test/std/language.support/support.dynamic/alloc.errors/set.new.handler/set_new_handler.pass.cpp
new file mode 100644
index 0000000000000..349bf440e0dc4
--- /dev/null
+++ b/test/std/language.support/support.dynamic/alloc.errors/set.new.handler/set_new_handler.pass.cpp
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test set_new_handler
+
+#include <new>
+#include <cassert>
+
+void f1() {}
+void f2() {}
+
+int main()
+{
+ assert(std::set_new_handler(f1) == 0);
+ assert(std::set_new_handler(f2) == f1);
+}
diff --git a/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array.pass.cpp b/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array.pass.cpp
new file mode 100644
index 0000000000000..5a87c07387844
--- /dev/null
+++ b/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array.pass.cpp
@@ -0,0 +1,57 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test operator new[]
+// NOTE: asan and msan will not call the new handler.
+// UNSUPPORTED: sanitizer-new-delete
+
+
+#include <new>
+#include <cstddef>
+#include <cassert>
+#include <limits>
+
+int new_handler_called = 0;
+
+void new_handler()
+{
+ ++new_handler_called;
+ std::set_new_handler(0);
+}
+
+int A_constructed = 0;
+
+struct A
+{
+ A() {++A_constructed;}
+ ~A() {--A_constructed;}
+};
+
+int main()
+{
+ std::set_new_handler(new_handler);
+ try
+ {
+ void*volatile vp = operator new[] (std::numeric_limits<std::size_t>::max());
+ assert(false);
+ }
+ catch (std::bad_alloc&)
+ {
+ assert(new_handler_called == 1);
+ }
+ catch (...)
+ {
+ assert(false);
+ }
+ A* ap = new A[3];
+ assert(ap);
+ assert(A_constructed == 3);
+ delete [] ap;
+ assert(A_constructed == 0);
+}
diff --git a/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow.pass.cpp b/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow.pass.cpp
new file mode 100644
index 0000000000000..b0db4a8e57e2a
--- /dev/null
+++ b/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow.pass.cpp
@@ -0,0 +1,54 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test operator new [] (nothrow)
+// NOTE: asan and msan will not call the new handler.
+// UNSUPPORTED: sanitizer-new-delete
+
+
+#include <new>
+#include <cstddef>
+#include <cassert>
+#include <limits>
+
+int new_handler_called = 0;
+
+void new_handler()
+{
+ ++new_handler_called;
+ std::set_new_handler(0);
+}
+
+int A_constructed = 0;
+
+struct A
+{
+ A() {++A_constructed;}
+ ~A() {--A_constructed;}
+};
+
+int main()
+{
+ std::set_new_handler(new_handler);
+ try
+ {
+ void*volatile vp = operator new [] (std::numeric_limits<std::size_t>::max(), std::nothrow);
+ assert(new_handler_called == 1);
+ assert(vp == 0);
+ }
+ catch (...)
+ {
+ assert(false);
+ }
+ A* ap = new(std::nothrow) A[3];
+ assert(ap);
+ assert(A_constructed == 3);
+ delete [] ap;
+ assert(A_constructed == 0);
+}
diff --git a/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow_replace.pass.cpp b/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow_replace.pass.cpp
new file mode 100644
index 0000000000000..105c7a93f210b
--- /dev/null
+++ b/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow_replace.pass.cpp
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test operator new [] nothrow by replacing only operator new
+
+// UNSUPPORTED: sanitizer-new-delete
+
+#include <new>
+#include <cstddef>
+#include <cstdlib>
+#include <cassert>
+#include <limits>
+
+int new_called = 0;
+
+void* operator new(std::size_t s) throw(std::bad_alloc)
+{
+ ++new_called;
+ return std::malloc(s);
+}
+
+void operator delete(void* p) throw()
+{
+ --new_called;
+ std::free(p);
+}
+
+volatile int A_constructed = 0;
+
+struct A
+{
+ A() {++A_constructed;}
+ ~A() {--A_constructed;}
+};
+
+int main()
+{
+ A* ap = new (std::nothrow) A[3];
+ assert(ap);
+ assert(A_constructed == 3);
+ assert(new_called);
+ delete [] ap;
+ assert(A_constructed == 0);
+ assert(!new_called);
+}
diff --git a/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_replace.pass.cpp b/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_replace.pass.cpp
new file mode 100644
index 0000000000000..92bd7b952dcbc
--- /dev/null
+++ b/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_replace.pass.cpp
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test operator new[] replacement by replacing only operator new
+
+// UNSUPPORTED: sanitizer-new-delete
+
+#include <new>
+#include <cstddef>
+#include <cstdlib>
+#include <cassert>
+#include <limits>
+
+volatile int new_called = 0;
+
+void* operator new(std::size_t s) throw(std::bad_alloc)
+{
+ ++new_called;
+ return std::malloc(s);
+}
+
+void operator delete(void* p) throw()
+{
+ --new_called;
+ std::free(p);
+}
+
+int A_constructed = 0;
+
+struct A
+{
+ A() {++A_constructed;}
+ ~A() {--A_constructed;}
+};
+
+int main()
+{
+ A* ap = new A[3];
+ assert(ap);
+ assert(A_constructed == 3);
+ assert(new_called == 1);
+ delete [] ap;
+ assert(A_constructed == 0);
+ assert(new_called == 0);
+}
diff --git a/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array11.pass.cpp b/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array11.pass.cpp
new file mode 100644
index 0000000000000..0f7840ca9ef89
--- /dev/null
+++ b/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array11.pass.cpp
@@ -0,0 +1,68 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test sized operator delete[] replacement.
+
+// Note that sized delete operator definitions below are simply ignored
+// when sized deallocation is not supported, e.g., prior to C++14.
+
+// UNSUPPORTED: c++14, c++1z
+// UNSUPPORTED: sanitizer-new-delete
+
+#include <new>
+#include <cstddef>
+#include <cstdlib>
+#include <cassert>
+
+int unsized_delete_called = 0;
+int unsized_delete_nothrow_called = 0;
+int sized_delete_called = 0;
+
+void operator delete[](void* p) throw()
+{
+ ++unsized_delete_called;
+ std::free(p);
+}
+
+void operator delete[](void* p, const std::nothrow_t&) throw()
+{
+ ++unsized_delete_nothrow_called;
+ std::free(p);
+}
+
+void operator delete[](void* p, std::size_t) throw()
+{
+ ++sized_delete_called;
+ std::free(p);
+}
+
+// NOTE: Use a class with a non-trivial destructor as the test type in order
+// to ensure the correct overload is called.
+// C++14 5.3.5 [expr.delete]p10
+// - If the type is complete and if, for the second alternative (delete array)
+// only, the operand is a pointer to a class type with a non-trivial
+// destructor or a (possibly multi-dimensional) array thereof, the function
+// with two parameters is selected.
+// - Otherwise, it is unspecified which of the two deallocation functions is
+// selected.
+struct A { ~A() {} };
+
+int main()
+{
+
+ A* x = new A[3];
+ assert(0 == unsized_delete_called);
+ assert(0 == unsized_delete_nothrow_called);
+ assert(0 == sized_delete_called);
+
+ delete [] x;
+ assert(1 == unsized_delete_called);
+ assert(0 == sized_delete_called);
+ assert(0 == unsized_delete_nothrow_called);
+}
diff --git a/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array14.pass.cpp b/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array14.pass.cpp
new file mode 100644
index 0000000000000..6447e29726c1c
--- /dev/null
+++ b/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array14.pass.cpp
@@ -0,0 +1,73 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test sized operator delete[] replacement.
+
+// UNSUPPORTED: sanitizer-new-delete, c++98, c++03, c++11
+
+// TODO: Clang does not enable sized-deallocation in c++14 and behond by
+// default. It is only enabled when -fsized-deallocation is given.
+// (except clang-3.6 which temporarly enabled sized-deallocation)
+// XFAIL: clang-3.4, clang-3.5, clang-3.7
+// XFAIL: apple-clang
+
+// NOTE: GCC 4.9.1 does not support sized-deallocation in c++14. However
+// GCC 5.1 does.
+// XFAIL: gcc-4.7, gcc-4.8, gcc-4.9
+
+#include <new>
+#include <cstddef>
+#include <cstdlib>
+#include <cassert>
+
+int unsized_delete_called = 0;
+int unsized_delete_nothrow_called = 0;
+int sized_delete_called = 0;
+
+void operator delete[](void* p) throw()
+{
+ ++unsized_delete_called;
+ std::free(p);
+}
+
+void operator delete[](void* p, const std::nothrow_t&) throw()
+{
+ ++unsized_delete_nothrow_called;
+ std::free(p);
+}
+
+void operator delete[](void* p, std::size_t) throw()
+{
+ ++sized_delete_called;
+ std::free(p);
+}
+
+// NOTE: Use a class with a non-trivial destructor as the test type in order
+// to ensure the correct overload is called.
+// C++14 5.3.5 [expr.delete]p10
+// - If the type is complete and if, for the second alternative (delete array)
+// only, the operand is a pointer to a class type with a non-trivial
+// destructor or a (possibly multi-dimensional) array thereof, the function
+// with two parameters is selected.
+// - Otherwise, it is unspecified which of the two deallocation functions is
+// selected.
+struct A { ~A() {} };
+
+int main()
+{
+ A* x = new A[3];
+ assert(0 == unsized_delete_called);
+ assert(0 == unsized_delete_nothrow_called);
+ assert(0 == sized_delete_called);
+
+ delete [] x;
+ assert(0 == unsized_delete_called);
+ assert(0 == unsized_delete_nothrow_called);
+ assert(1 == sized_delete_called);
+}
diff --git a/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array_calls_unsized_delete_array.pass.cpp b/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array_calls_unsized_delete_array.pass.cpp
new file mode 100644
index 0000000000000..6d24aec35ef8a
--- /dev/null
+++ b/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array_calls_unsized_delete_array.pass.cpp
@@ -0,0 +1,56 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test sized operator [] delete calls the unsized operator [] delete.
+// When sized operator delete [] is not available (ex C++11) then the unsized
+// operator delete [] is called directly.
+
+// UNSUPPORTED: sanitizer-new-delete
+
+#include <new>
+#include <cstddef>
+#include <cstdlib>
+#include <cassert>
+
+int delete_called = 0;
+int delete_nothrow_called = 0;
+
+void operator delete[](void* p) throw()
+{
+ ++delete_called;
+ std::free(p);
+}
+
+void operator delete[](void* p, const std::nothrow_t&) throw()
+{
+ ++delete_nothrow_called;
+ std::free(p);
+}
+
+// NOTE: Use a class with a non-trivial destructor as the test type in order
+// to ensure the correct overload is called.
+// C++14 5.3.5 [expr.delete]p10
+// - If the type is complete and if, for the second alternative (delete array)
+// only, the operand is a pointer to a class type with a non-trivial
+// destructor or a (possibly multi-dimensional) array thereof, the function
+// with two parameters is selected.
+// - Otherwise, it is unspecified which of the two deallocation functions is
+// selected.
+struct A { ~A() {} };
+
+int main()
+{
+ A* x = new A[3];
+ assert(0 == delete_called);
+ assert(0 == delete_nothrow_called);
+
+ delete [] x;
+ assert(1 == delete_called);
+ assert(0 == delete_nothrow_called);
+}
diff --git a/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array_fsizeddeallocation.sh.cpp b/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array_fsizeddeallocation.sh.cpp
new file mode 100644
index 0000000000000..7dd510b4dac83
--- /dev/null
+++ b/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array_fsizeddeallocation.sh.cpp
@@ -0,0 +1,80 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test sized operator delete[] replacement.
+
+// Note that sized delete operator definitions below are simply ignored
+// when sized deallocation is not supported, e.g., prior to C++14.
+
+// UNSUPPORTED: sanitizer-new-delete
+
+// NOTE: Only clang-3.7 and GCC 5.1 and greater support -fsized-deallocation.
+// REQUIRES: fsized-deallocation
+
+// RUN: %build -fsized-deallocation
+// RUN: %run
+
+#if !defined(__cpp_sized_deallocation)
+# error __cpp_sized_deallocation should be defined
+#endif
+
+#if !(__cpp_sized_deallocation >= 201309L)
+# error expected __cpp_sized_deallocation >= 201309L
+#endif
+
+#include <new>
+#include <cstddef>
+#include <cstdlib>
+#include <cassert>
+
+int unsized_delete_called = 0;
+int unsized_delete_nothrow_called = 0;
+int sized_delete_called = 0;
+
+void operator delete[](void* p) throw()
+{
+ ++unsized_delete_called;
+ std::free(p);
+}
+
+void operator delete[](void* p, const std::nothrow_t&) throw()
+{
+ ++unsized_delete_nothrow_called;
+ std::free(p);
+}
+
+void operator delete[](void* p, std::size_t) throw()
+{
+ ++sized_delete_called;
+ std::free(p);
+}
+
+// NOTE: Use a class with a non-trivial destructor as the test type in order
+// to ensure the correct overload is called.
+// C++14 5.3.5 [expr.delete]p10
+// - If the type is complete and if, for the second alternative (delete array)
+// only, the operand is a pointer to a class type with a non-trivial
+// destructor or a (possibly multi-dimensional) array thereof, the function
+// with two parameters is selected.
+// - Otherwise, it is unspecified which of the two deallocation functions is
+// selected.
+struct A { ~A() {} };
+
+int main()
+{
+ A* x = new A[3];
+ assert(0 == unsized_delete_called);
+ assert(0 == unsized_delete_nothrow_called);
+ assert(0 == sized_delete_called);
+
+ delete [] x;
+ assert(0 == unsized_delete_called);
+ assert(0 == unsized_delete_nothrow_called);
+ assert(1 == sized_delete_called);
+}
diff --git a/test/std/language.support/support.dynamic/new.delete/new.delete.dataraces/not_testable.pass.cpp b/test/std/language.support/support.dynamic/new.delete/new.delete.dataraces/not_testable.pass.cpp
new file mode 100644
index 0000000000000..b58f5c55b643a
--- /dev/null
+++ b/test/std/language.support/support.dynamic/new.delete/new.delete.dataraces/not_testable.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/test/std/language.support/support.dynamic/new.delete/new.delete.placement/new.pass.cpp b/test/std/language.support/support.dynamic/new.delete/new.delete.placement/new.pass.cpp
new file mode 100644
index 0000000000000..ad306e06cb78b
--- /dev/null
+++ b/test/std/language.support/support.dynamic/new.delete/new.delete.placement/new.pass.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test placement new
+
+#include <new>
+#include <cassert>
+
+int A_constructed = 0;
+
+struct A
+{
+ A() {++A_constructed;}
+ ~A() {--A_constructed;}
+};
+
+int main()
+{
+ char buf[sizeof(A)];
+
+ A* ap = new(buf) A;
+ assert((char*)ap == buf);
+ assert(A_constructed == 1);
+}
diff --git a/test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_array.pass.cpp b/test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_array.pass.cpp
new file mode 100644
index 0000000000000..1ab52ae4c8dfb
--- /dev/null
+++ b/test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_array.pass.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test placement new array
+
+#include <new>
+#include <cassert>
+
+int A_constructed = 0;
+
+struct A
+{
+ A() {++A_constructed;}
+ ~A() {--A_constructed;}
+};
+
+int main()
+{
+ char buf[3*sizeof(A)];
+
+ A* ap = new(buf) A[3];
+ assert((char*)ap == buf);
+ assert(A_constructed == 3);
+}
diff --git a/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.pass.cpp b/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.pass.cpp
new file mode 100644
index 0000000000000..58aa3f2d529c4
--- /dev/null
+++ b/test/std/language.support/support.dynamic/new.delete/new.delete.single/new.pass.cpp
@@ -0,0 +1,57 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test operator new
+
+// asan and msan will not call the new handler.
+// UNSUPPORTED: sanitizer-new-delete
+
+#include <new>
+#include <cstddef>
+#include <cassert>
+#include <limits>
+
+int new_handler_called = 0;
+
+void new_handler()
+{
+ ++new_handler_called;
+ std::set_new_handler(0);
+}
+
+bool A_constructed = false;
+
+struct A
+{
+ A() {A_constructed = true;}
+ ~A() {A_constructed = false;}
+};
+
+int main()
+{
+ std::set_new_handler(new_handler);
+ try
+ {
+ void* vp = operator new (std::numeric_limits<std::size_t>::max());
+ assert(false);
+ }
+ catch (std::bad_alloc&)
+ {
+ assert(new_handler_called == 1);
+ }
+ catch (...)
+ {
+ assert(false);
+ }
+ A* ap = new A;
+ assert(ap);
+ assert(A_constructed);
+ delete ap;
+ assert(!A_constructed);
+}
diff --git a/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow.pass.cpp b/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow.pass.cpp
new file mode 100644
index 0000000000000..8c095ad32db42
--- /dev/null
+++ b/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow.pass.cpp
@@ -0,0 +1,54 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test operator new (nothrow)
+
+// asan and msan will not call the new handler.
+// UNSUPPORTED: sanitizer-new-delete
+
+#include <new>
+#include <cstddef>
+#include <cassert>
+#include <limits>
+
+int new_handler_called = 0;
+
+void new_handler()
+{
+ ++new_handler_called;
+ std::set_new_handler(0);
+}
+
+bool A_constructed = false;
+
+struct A
+{
+ A() {A_constructed = true;}
+ ~A() {A_constructed = false;}
+};
+
+int main()
+{
+ std::set_new_handler(new_handler);
+ try
+ {
+ void* vp = operator new (std::numeric_limits<std::size_t>::max(), std::nothrow);
+ assert(new_handler_called == 1);
+ assert(vp == 0);
+ }
+ catch (...)
+ {
+ assert(false);
+ }
+ A* ap = new(std::nothrow) A;
+ assert(ap);
+ assert(A_constructed);
+ delete ap;
+ assert(!A_constructed);
+}
diff --git a/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow_replace.pass.cpp b/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow_replace.pass.cpp
new file mode 100644
index 0000000000000..cd70f90948d2d
--- /dev/null
+++ b/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow_replace.pass.cpp
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test operator new nothrow by replacing only operator new
+
+// UNSUPPORTED: sanitizer-new-delete
+
+#include <new>
+#include <cstddef>
+#include <cstdlib>
+#include <cassert>
+#include <limits>
+
+int new_called = 0;
+
+void* operator new(std::size_t s) throw(std::bad_alloc)
+{
+ ++new_called;
+ return std::malloc(s);
+}
+
+void operator delete(void* p) throw()
+{
+ --new_called;
+ std::free(p);
+}
+
+bool A_constructed = false;
+
+struct A
+{
+ A() {A_constructed = true;}
+ ~A() {A_constructed = false;}
+};
+
+int main()
+{
+ A* ap = new (std::nothrow) A;
+ assert(ap);
+ assert(A_constructed);
+ assert(new_called);
+ delete ap;
+ assert(!A_constructed);
+ assert(!new_called);
+}
diff --git a/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_replace.pass.cpp b/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_replace.pass.cpp
new file mode 100644
index 0000000000000..0df3a93703d21
--- /dev/null
+++ b/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_replace.pass.cpp
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test operator new replacement
+
+// UNSUPPORTED: sanitizer-new-delete
+
+#include <new>
+#include <cstddef>
+#include <cstdlib>
+#include <cassert>
+#include <limits>
+
+int new_called = 0;
+
+void* operator new(std::size_t s) throw(std::bad_alloc)
+{
+ ++new_called;
+ return std::malloc(s);
+}
+
+void operator delete(void* p) throw()
+{
+ --new_called;
+ std::free(p);
+}
+
+bool A_constructed = false;
+
+struct A
+{
+ A() {A_constructed = true;}
+ ~A() {A_constructed = false;}
+};
+
+int main()
+{
+ A* ap = new A;
+ assert(ap);
+ assert(A_constructed);
+ assert(new_called);
+ delete ap;
+ assert(!A_constructed);
+ assert(!new_called);
+}
diff --git a/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete11.pass.cpp b/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete11.pass.cpp
new file mode 100644
index 0000000000000..e4064e2ab5109
--- /dev/null
+++ b/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete11.pass.cpp
@@ -0,0 +1,56 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test sized operator delete replacement.
+
+// Note that sized delete operator definitions below are simply ignored
+// when sized deallocation is not supported, e.g., prior to C++14.
+
+// UNSUPPORTED: c++14, c++1z
+// UNSUPPORTED: sanitizer-new-delete
+
+#include <new>
+#include <cstddef>
+#include <cstdlib>
+#include <cassert>
+
+int unsized_delete_called = 0;
+int unsized_delete_nothrow_called = 0;
+int sized_delete_called = 0;
+
+void operator delete(void* p) throw()
+{
+ ++unsized_delete_called;
+ std::free(p);
+}
+
+void operator delete(void* p, const std::nothrow_t&) throw()
+{
+ ++unsized_delete_nothrow_called;
+ std::free(p);
+}
+
+void operator delete(void* p, std::size_t) throw()
+{
+ ++sized_delete_called;
+ std::free(p);
+}
+
+int main()
+{
+ int *x = new int(42);
+ assert(0 == unsized_delete_called);
+ assert(0 == unsized_delete_nothrow_called);
+ assert(0 == sized_delete_called);
+
+ delete x;
+ assert(1 == unsized_delete_called);
+ assert(0 == sized_delete_called);
+ assert(0 == unsized_delete_nothrow_called);
+}
diff --git a/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete14.pass.cpp b/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete14.pass.cpp
new file mode 100644
index 0000000000000..3c7f54fef726a
--- /dev/null
+++ b/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete14.pass.cpp
@@ -0,0 +1,62 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test sized operator delete replacement.
+
+// UNSUPPORTED: sanitizer-new-delete, c++98, c++03, c++11
+
+// TODO: Clang does not enable sized-deallocation in c++14 and behond by
+// default. It is only enabled when -fsized-deallocation is given.
+// (except clang-3.6 which temporarly enabled sized-deallocation)
+// XFAIL: clang-3.4, clang-3.5, clang-3.7
+// XFAIL: apple-clang
+
+// NOTE: GCC 4.9.1 does not support sized-deallocation in c++14. However
+// GCC 5.1 does.
+// XFAIL: gcc-4.7, gcc-4.8, gcc-4.9
+
+#include <new>
+#include <cstddef>
+#include <cstdlib>
+#include <cassert>
+
+int unsized_delete_called = 0;
+int unsized_delete_nothrow_called = 0;
+int sized_delete_called = 0;
+
+void operator delete(void* p) throw()
+{
+ ++unsized_delete_called;
+ std::free(p);
+}
+
+void operator delete(void* p, const std::nothrow_t&) throw()
+{
+ ++unsized_delete_nothrow_called;
+ std::free(p);
+}
+
+void operator delete(void* p, std::size_t) throw()
+{
+ ++sized_delete_called;
+ std::free(p);
+}
+
+int main()
+{
+ int *x = new int(42);
+ assert(0 == unsized_delete_called);
+ assert(0 == unsized_delete_nothrow_called);
+ assert(0 == sized_delete_called);
+
+ delete x;
+ assert(0 == unsized_delete_called);
+ assert(1 == sized_delete_called);
+ assert(0 == unsized_delete_nothrow_called);
+}
diff --git a/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete_calls_unsized_delete.pass.cpp b/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete_calls_unsized_delete.pass.cpp
new file mode 100644
index 0000000000000..5c4eba53d3e4d
--- /dev/null
+++ b/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete_calls_unsized_delete.pass.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test sized operator delete calls the unsized operator delete.
+// When sized operator delete is not available (ex C++11) then the unsized
+// operator delete is called directly.
+
+// UNSUPPORTED: sanitizer-new-delete
+
+#include <new>
+#include <cstddef>
+#include <cstdlib>
+#include <cassert>
+
+int delete_called = 0;
+int delete_nothrow_called = 0;
+
+void operator delete(void* p) throw()
+{
+ ++delete_called;
+ std::free(p);
+}
+
+void operator delete(void* p, const std::nothrow_t&) throw()
+{
+ ++delete_nothrow_called;
+ std::free(p);
+}
+
+int main()
+{
+ int *x = new int(42);
+ assert(0 == delete_called);
+ assert(0 == delete_nothrow_called);
+
+ delete x;
+ assert(1 == delete_called);
+ assert(0 == delete_nothrow_called);
+}
diff --git a/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete_fsizeddeallocation.sh.cpp b/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete_fsizeddeallocation.sh.cpp
new file mode 100644
index 0000000000000..da43d49691742
--- /dev/null
+++ b/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete_fsizeddeallocation.sh.cpp
@@ -0,0 +1,69 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test sized operator delete replacement.
+
+// Note that sized delete operator definitions below are simply ignored
+// when sized deallocation is not supported, e.g., prior to C++14.
+
+// UNSUPPORTED: sanitizer-new-delete
+
+// NOTE: Only clang-3.7 and GCC 5.1 and greater support -fsized-deallocation.
+// REQUIRES: fsized-deallocation
+
+// RUN: %build -fsized-deallocation
+// RUN: %run
+
+#if !defined(__cpp_sized_deallocation)
+# error __cpp_sized_deallocation should be defined
+#endif
+
+#if !(__cpp_sized_deallocation >= 201309L)
+# error expected __cpp_sized_deallocation >= 201309L
+#endif
+
+#include <new>
+#include <cstddef>
+#include <cstdlib>
+#include <cassert>
+
+int unsized_delete_called = 0;
+int unsized_delete_nothrow_called = 0;
+int sized_delete_called = 0;
+
+void operator delete(void* p) throw()
+{
+ ++unsized_delete_called;
+ std::free(p);
+}
+
+void operator delete(void* p, const std::nothrow_t&) throw()
+{
+ ++unsized_delete_nothrow_called;
+ std::free(p);
+}
+
+void operator delete(void* p, std::size_t) throw()
+{
+ ++sized_delete_called;
+ std::free(p);
+}
+
+int main()
+{
+ int *x = new int(42);
+ assert(0 == sized_delete_called);
+ assert(0 == unsized_delete_called);
+ assert(0 == unsized_delete_nothrow_called);
+
+ delete x;
+ assert(1 == sized_delete_called);
+ assert(0 == unsized_delete_called);
+ assert(0 == unsized_delete_nothrow_called);
+}
diff --git a/test/std/language.support/support.dynamic/new.delete/nothing_to_do.pass.cpp b/test/std/language.support/support.dynamic/new.delete/nothing_to_do.pass.cpp
new file mode 100644
index 0000000000000..b58f5c55b643a
--- /dev/null
+++ b/test/std/language.support/support.dynamic/new.delete/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/test/std/language.support/support.dynamic/version.pass.cpp b/test/std/language.support/support.dynamic/version.pass.cpp
new file mode 100644
index 0000000000000..ba1ff518e51f0
--- /dev/null
+++ b/test/std/language.support/support.dynamic/version.pass.cpp
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <new>
+
+#include <new>
+
+#ifndef _LIBCPP_VERSION
+#error _LIBCPP_VERSION not defined
+#endif
+
+int main()
+{
+}