Bug 1814798 - pt 1. Add bool to enable/disable PHC at runtime r=glandium
[gecko.git] / build / clang-plugin / tests / TestCustomHeap.cpp
blobc1e82f2fa7b5d00803cbfdf8e760f015f44e1942
1 #define MOZ_NONHEAP_CLASS __attribute__((annotate("moz_nonheap_class")))
2 #ifndef MOZ_HEAP_ALLOCATOR
3 #define MOZ_HEAP_ALLOCATOR \
4 _Pragma("GCC diagnostic push") \
5 _Pragma("GCC diagnostic ignored \"-Wgcc-compat\"") \
6 __attribute__((annotate("moz_heap_allocator"))) \
7 _Pragma("GCC diagnostic pop")
8 #endif
10 #include <stdlib.h>
11 #include <memory>
13 struct MOZ_NONHEAP_CLASS X {
16 void *operator new(size_t x, int qual) MOZ_HEAP_ALLOCATOR {
17 return ::operator new(x);
20 template <typename T>
21 T *customAlloc() MOZ_HEAP_ALLOCATOR {
22 T *arg = static_cast<T*>(malloc(sizeof(T)));
23 return new (arg) T();
26 void misuseX() {
27 X *foo = customAlloc<X>(); // expected-error {{variable of type 'X' is not valid on the heap}} expected-note {{value incorrectly allocated on the heap}}
28 X *foo2 = new (100) X(); // expected-error {{variable of type 'X' is not valid on the heap}} expected-note {{value incorrectly allocated on the heap}}