| 1 |
// { dg-do compile } |
| 2 |
// { dg-options "-O2 -fdump-tree-gimple -fdump-tree-optimized" } |
| 3 |
// { dg-final { scan-tree-dump " = operator new \\\(" "gimple" } } |
| 4 |
// { dg-final { scan-tree-dump "operator delete \\\(" "gimple" } } |
| 5 |
// { dg-final { scan-tree-dump-not "operator new \\\(" "optimized" } } |
| 6 |
// { dg-final { scan-tree-dump-not "operator delete \\\(" "optimized" } } |
| 7 |
|
| 8 |
#include <new> |
| 9 |
|
| 10 |
#if __has_builtin (__builtin_operator_new) != 201802L |
| 11 |
#error "Unexpected value of __has_builtin (__builtin_operator_new)" |
| 12 |
#endif |
| 13 |
#if __has_builtin (__builtin_operator_delete) != 201802L |
| 14 |
#error "Unexpected value of __has_builtin (__builtin_operator_delete)" |
| 15 |
#endif |
| 16 |
|
| 17 |
void |
| 18 |
foo () |
| 19 |
{ |
| 20 |
void *a = __builtin_operator_new (32); |
| 21 |
__builtin_operator_delete (a); |
| 22 |
#if __cpp_sized_deallocation |
| 23 |
a = __builtin_operator_new (32); |
| 24 |
__builtin_operator_delete (a, 32); |
| 25 |
#endif |
| 26 |
#if __cpp_aligned_new |
| 27 |
void *b = __builtin_operator_new (32, std::align_val_t(32)); |
| 28 |
__builtin_operator_delete (b, std::align_val_t(32)); |
| 29 |
#if __cpp_sized_deallocation |
| 30 |
b = __builtin_operator_new (32, std::align_val_t(32)); |
| 31 |
__builtin_operator_delete (b, 32, std::align_val_t(32)); |
| 32 |
#endif |
| 33 |
#endif |
| 34 |
void *c = __builtin_operator_new (32, std::nothrow); |
| 35 |
__builtin_operator_delete (c, std::nothrow); |
| 36 |
#if __cpp_aligned_new |
| 37 |
void *d = __builtin_operator_new (32, std::align_val_t(32), std::nothrow); |
| 38 |
__builtin_operator_delete (d, std::align_val_t(32), std::nothrow); |
| 39 |
#endif |
| 40 |
void *e = __builtin_operator_new (1.f); |
| 41 |
__builtin_operator_delete (e); |
| 42 |
} |
| 43 |
|
| 44 |
template <int N> |
| 45 |
void |
| 46 |
bar () |
| 47 |
{ |
| 48 |
void *a = __builtin_operator_new (32); |
| 49 |
__builtin_operator_delete (a); |
| 50 |
#if __cpp_sized_deallocation |
| 51 |
a = __builtin_operator_new (32); |
| 52 |
__builtin_operator_delete (a, 32); |
| 53 |
#endif |
| 54 |
#if __cpp_aligned_new |
| 55 |
void *b = __builtin_operator_new (32, std::align_val_t(32)); |
| 56 |
__builtin_operator_delete (b, std::align_val_t(32)); |
| 57 |
#if __cpp_sized_deallocation |
| 58 |
b = __builtin_operator_new (32, std::align_val_t(32)); |
| 59 |
__builtin_operator_delete (b, 32, std::align_val_t(32)); |
| 60 |
#endif |
| 61 |
#endif |
| 62 |
void *c = __builtin_operator_new (32, std::nothrow); |
| 63 |
__builtin_operator_delete (c, std::nothrow); |
| 64 |
#if __cpp_aligned_new |
| 65 |
void *d = __builtin_operator_new (32, std::align_val_t(32), std::nothrow); |
| 66 |
__builtin_operator_delete (d, std::align_val_t(32), std::nothrow); |
| 67 |
#endif |
| 68 |
void *e = __builtin_operator_new (1.f); |
| 69 |
__builtin_operator_delete (e); |
| 70 |
} |
| 71 |
|
| 72 |
template <typename T, typename U, typename V, typename W> |
| 73 |
void |
| 74 |
baz (T sz, V v, W w) |
| 75 |
{ |
| 76 |
U a = __builtin_operator_new (sz); |
| 77 |
__builtin_operator_delete (a); |
| 78 |
#if __cpp_sized_deallocation |
| 79 |
a = __builtin_operator_new (sz); |
| 80 |
__builtin_operator_delete (a, sz); |
| 81 |
#endif |
| 82 |
#if __cpp_aligned_new |
| 83 |
U b = __builtin_operator_new (sz, std::align_val_t(sz)); |
| 84 |
__builtin_operator_delete (b, std::align_val_t(sz)); |
| 85 |
#if __cpp_sized_deallocation |
| 86 |
b = __builtin_operator_new (sz, std::align_val_t(sz)); |
| 87 |
__builtin_operator_delete (b, sz, std::align_val_t(sz)); |
| 88 |
#endif |
| 89 |
#endif |
| 90 |
U c = __builtin_operator_new (sz, v); |
| 91 |
__builtin_operator_delete (c, v); |
| 92 |
#if __cpp_aligned_new |
| 93 |
U d = __builtin_operator_new (sz, std::align_val_t(sz), v); |
| 94 |
__builtin_operator_delete (d, std::align_val_t(sz), v); |
| 95 |
#endif |
| 96 |
U e = __builtin_operator_new (w); |
| 97 |
__builtin_operator_delete (e); |
| 98 |
} |
| 99 |
|
| 100 |
void |
| 101 |
qux () |
| 102 |
{ |
| 103 |
bar <0> (); |
| 104 |
baz <std::size_t, void *, const std::nothrow_t &, float> (32, std::nothrow, |
| 105 |
1.f); |
| 106 |
} |