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.

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

mercurial