build/clang-plugin/tests/TestCustomHeap.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 #define MOZ_NONHEAP_CLASS __attribute__((annotate("moz_nonheap_class")))
michael@0 2 #define MOZ_HEAP_ALLOCATOR \
michael@0 3 _Pragma("GCC diagnostic push") \
michael@0 4 _Pragma("GCC diagnostic ignored \"-Wgcc-compat\"") \
michael@0 5 __attribute__((annotate("moz_heap_allocator"))) \
michael@0 6 _Pragma("GCC diagnostic pop")
michael@0 7
michael@0 8 #include <stdlib.h>
michael@0 9 #include <memory>
michael@0 10
michael@0 11 struct MOZ_NONHEAP_CLASS X {
michael@0 12 };
michael@0 13
michael@0 14 void *operator new(size_t x, int qual) MOZ_HEAP_ALLOCATOR {
michael@0 15 return ::operator new(x);
michael@0 16 }
michael@0 17
michael@0 18 template <typename T>
michael@0 19 T *customAlloc() MOZ_HEAP_ALLOCATOR {
michael@0 20 T *arg = static_cast<T*>(malloc(sizeof(T)));
michael@0 21 return new (arg) T();
michael@0 22 }
michael@0 23
michael@0 24 template <typename T>
michael@0 25 void misuseX(T q) {
michael@0 26 X *foo = customAlloc<X>(); // expected-error {{variable of type 'X' is not valid on the heap}}
michael@0 27 X *foo2 = new (100) X(); // expected-error {{variable of type 'X' is not valid on the heap}}
michael@0 28 }

mercurial