forked from OSchip/llvm-project
Prevent new/delete replacement tests from being optimized away.
llvm-svn: 284289
This commit is contained in:
parent
8bbc3158c3
commit
d2003575ce
|
@ -15,10 +15,7 @@
|
|||
// XFAIL: clang-3, apple-clang
|
||||
|
||||
// None of the current GCC compilers support this.
|
||||
// XFAIL: gcc-4, gcc-5, gcc-6
|
||||
|
||||
// TODO Investigate why UBSAN prevents new from calling our replacement.
|
||||
// XFAIL: ubsan
|
||||
// XFAIL: gcc
|
||||
|
||||
#include <new>
|
||||
#include <cstddef>
|
||||
|
@ -58,28 +55,31 @@ void operator delete [] (void* p, std::align_val_t a) throw()
|
|||
struct alignas(OverAligned) A {};
|
||||
struct alignas(std::max_align_t) B {};
|
||||
|
||||
B* volatile b; // Escape the memory
|
||||
A* volatile a;
|
||||
|
||||
int main()
|
||||
{
|
||||
reset();
|
||||
{
|
||||
B *x = new B[2];
|
||||
b = new B[2];
|
||||
assert(0 == unsized_delete_called);
|
||||
assert(0 == unsized_delete_nothrow_called);
|
||||
assert(0 == aligned_delete_called);
|
||||
|
||||
delete [] x;
|
||||
delete [] b;
|
||||
assert(1 == unsized_delete_called);
|
||||
assert(0 == unsized_delete_nothrow_called);
|
||||
assert(0 == aligned_delete_called);
|
||||
}
|
||||
reset();
|
||||
{
|
||||
A *x = new A[2];
|
||||
a = new A[2];
|
||||
assert(0 == unsized_delete_called);
|
||||
assert(0 == unsized_delete_nothrow_called);
|
||||
assert(0 == aligned_delete_called);
|
||||
|
||||
delete [] x;
|
||||
delete [] a;
|
||||
assert(0 == unsized_delete_called);
|
||||
assert(0 == unsized_delete_nothrow_called);
|
||||
assert(1 == aligned_delete_called);
|
||||
|
|
|
@ -11,10 +11,6 @@
|
|||
|
||||
// UNSUPPORTED: sanitizer-new-delete
|
||||
|
||||
// TODO Investigate why UBSAN prevents new from calling our replacement.
|
||||
// XFAIL: ubsan
|
||||
|
||||
|
||||
#include <new>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
|
@ -45,9 +41,11 @@ struct A
|
|||
~A() {--A_constructed;}
|
||||
};
|
||||
|
||||
A* volatile ap;
|
||||
|
||||
int main()
|
||||
{
|
||||
A* ap = new (std::nothrow) A[3];
|
||||
ap = new (std::nothrow) A[3];
|
||||
assert(ap);
|
||||
assert(A_constructed == 3);
|
||||
assert(new_called);
|
||||
|
|
|
@ -11,9 +11,6 @@
|
|||
|
||||
// UNSUPPORTED: sanitizer-new-delete
|
||||
|
||||
// TODO Investigate why UBSAN prevents new from calling our replacement.
|
||||
// XFAIL: ubsan
|
||||
|
||||
|
||||
#include <new>
|
||||
#include <cstddef>
|
||||
|
@ -45,9 +42,11 @@ struct A
|
|||
~A() {--A_constructed;}
|
||||
};
|
||||
|
||||
A* volatile ap;
|
||||
|
||||
int main()
|
||||
{
|
||||
A* ap = new A[3];
|
||||
ap = new A[3];
|
||||
assert(ap);
|
||||
assert(A_constructed == 3);
|
||||
assert(new_called == 1);
|
||||
|
|
|
@ -15,10 +15,8 @@
|
|||
// XFAIL: clang-3, apple-clang
|
||||
|
||||
// None of the current GCC compilers support this.
|
||||
// XFAIL: gcc-4, gcc-5, gcc-6
|
||||
// XFAIL: gcc
|
||||
|
||||
// TODO Investigate why UBSAN prevents new from calling our replacement.
|
||||
// XFAIL: ubsan
|
||||
|
||||
#include <new>
|
||||
#include <cstddef>
|
||||
|
@ -58,28 +56,31 @@ void operator delete(void* p, std::align_val_t a) throw()
|
|||
struct alignas(OverAligned) A {};
|
||||
struct alignas(std::max_align_t) B {};
|
||||
|
||||
B* volatile bp;
|
||||
A* volatile ap;
|
||||
|
||||
int main()
|
||||
{
|
||||
reset();
|
||||
{
|
||||
B *x = new B;
|
||||
bp = new B;
|
||||
assert(0 == unsized_delete_called);
|
||||
assert(0 == unsized_delete_nothrow_called);
|
||||
assert(0 == aligned_delete_called);
|
||||
|
||||
delete x;
|
||||
delete bp;
|
||||
assert(1 == unsized_delete_called);
|
||||
assert(0 == unsized_delete_nothrow_called);
|
||||
assert(0 == aligned_delete_called);
|
||||
}
|
||||
reset();
|
||||
{
|
||||
A *x = new A;
|
||||
ap = new A;
|
||||
assert(0 == unsized_delete_called);
|
||||
assert(0 == unsized_delete_nothrow_called);
|
||||
assert(0 == aligned_delete_called);
|
||||
|
||||
delete x;
|
||||
delete ap;
|
||||
assert(0 == unsized_delete_called);
|
||||
assert(0 == unsized_delete_nothrow_called);
|
||||
assert(1 == aligned_delete_called);
|
||||
|
|
|
@ -11,9 +11,6 @@
|
|||
|
||||
// UNSUPPORTED: sanitizer-new-delete
|
||||
|
||||
// TODO Investigate why UBSAN prevents nothrow new from calling our replacement.
|
||||
// XFAIL: ubsan
|
||||
|
||||
#include <new>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
|
@ -44,9 +41,11 @@ struct A
|
|||
~A() {A_constructed = false;}
|
||||
};
|
||||
|
||||
A* volatile ap;
|
||||
|
||||
int main()
|
||||
{
|
||||
A* ap = new (std::nothrow) A;
|
||||
ap = new (std::nothrow) A;
|
||||
assert(ap);
|
||||
assert(A_constructed);
|
||||
assert(new_called);
|
||||
|
|
|
@ -13,10 +13,6 @@
|
|||
|
||||
// UNSUPPORTED: sanitizer-new-delete
|
||||
|
||||
// TODO Investigate why UBSAN prevents new from calling our replacement.
|
||||
// XFAIL: ubsan
|
||||
|
||||
|
||||
#include <new>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
|
@ -37,9 +33,11 @@ void operator delete(void* p, const std::nothrow_t&) throw()
|
|||
std::free(p);
|
||||
}
|
||||
|
||||
int* volatile x;
|
||||
|
||||
int main()
|
||||
{
|
||||
int *x = new int(42);
|
||||
x = new int(42);
|
||||
assert(0 == delete_called);
|
||||
assert(0 == delete_nothrow_called);
|
||||
|
||||
|
|
|
@ -14,9 +14,6 @@
|
|||
|
||||
// UNSUPPORTED: sanitizer-new-delete
|
||||
|
||||
// TODO Investigate why UBSAN prevents new from calling our replacement.
|
||||
// XFAIL: ubsan
|
||||
|
||||
// NOTE: Only clang-3.7 and GCC 5.1 and greater support -fsized-deallocation.
|
||||
// REQUIRES: fsized-deallocation
|
||||
|
||||
|
@ -58,9 +55,11 @@ void operator delete(void* p, std::size_t) throw()
|
|||
std::free(p);
|
||||
}
|
||||
|
||||
int* volatile x;
|
||||
|
||||
int main()
|
||||
{
|
||||
int *x = new int(42);
|
||||
x = new int(42);
|
||||
assert(0 == sized_delete_called);
|
||||
assert(0 == unsized_delete_called);
|
||||
assert(0 == unsized_delete_nothrow_called);
|
||||
|
|
Loading…
Reference in New Issue