2 // { dg-options "-O1" }
3 // { dg-final { scan-assembler-not "abort" } }
5 typedef __SIZE_TYPE__ size_t;
15 virtual ~UDClass () { --n; }
21 char buf [sizeof (UDClass)];
26 #if defined (__arm__) && defined (__ARM_EABI__)
27 // On ARM EABI the cookie is always 8 bytes as per Section 3.2.2 of
28 // http://infocenter.arm.com/help/topic/com.arm.doc.ihi0041d/IHI0041D_cppabi.pdf
29 static const size_t cookie_size = 8;
31 // On all other targets, the cookie size is the size of size_t
32 // GCC, and ideally the C++ standard, should provide an API to
33 // retrieve this constant.)
34 static const size_t cookie_size = sizeof (size_t);
37 inline __attribute__ ((always_inline))
38 void* operator new[] (size_t n)
40 // Verify that array new is invoked with an argument large enough
41 // for the array and a size_t cookie to store the number of elements.
42 // (This holds for classes with user-defined types but not POD types).
44 if (n != N * sizeof (UDClass) + cookie_size) abort ();
48 inline __attribute__ ((always_inline))
49 void* operator new[] (size_t n, void *p)
51 // Verify that the default placement array new is invoked with
52 // an argument just large enough for the array (and no cookie),
53 // regardless of whether the type is a POD or class with a user
55 if (n != N * sizeof (UDClass)) abort ();
59 inline __attribute__ ((always_inline))
60 void* operator new[] (size_t n, POD *p)
62 // Verify that placement array new overload for a POD type is
63 // invoked with an argument large enough for the array and
65 if (n != N * sizeof (POD)) abort ();
69 inline __attribute__ ((always_inline))
70 void* operator new[] (size_t n, UDClass *p)
72 // Verify that placement array new overload for a class type with
73 // a user-defined ctor and dtor is invoked with an argument large
74 // enough for the array and a cookie.
75 if (n != N * sizeof (UDClass) + cookie_size) abort ();
79 // UDClassllocate a sufficiently large buffer to construct arrays into.
80 static unsigned char buf [N * N];
84 // Avoid testing PODs since for those, the global new is invoked
85 // without the overhead of a cookie.
86 // return new POD [N];
90 POD* test_default_placement_new_POD ()
92 // Vefify that no overhead is allocated.
93 return new (buf) POD [N];
96 POD* test_overloaded_placement_new_POD ()
98 // Vefify that no overhead is allocated.
99 return new ((POD*)buf) POD [N];
102 UDClass* test_new_UDClass ()
104 // Vefify that space for a cookie is allocated.
105 return new UDClass [N];
108 UDClass* test_default_placement_new_UDClass ()
110 // Vefify that no overhead is allocated.
111 return new (buf) UDClass [N];
114 UDClass* test_overloaded_placement_new_UDClass ()
116 // Vefify that space for a cookie is allocated.
117 return new ((UDClass*)buf) UDClass [N];