Bug 1814798 - pt 1. Add bool to enable/disable PHC at runtime r=glandium
[gecko.git] / build / clang-plugin / tests / TestGlobalClass.cpp
blob7ce9c8d463061e30390afae1d0a57e4328dd33ac
1 #define MOZ_GLOBAL_CLASS __attribute__((annotate("moz_global_class")))
2 #include <stddef.h>
4 struct MOZ_GLOBAL_CLASS Global {
5 int i;
6 void *operator new(size_t x) throw() { return 0; }
7 void *operator new(size_t blah, char *buffer) { return buffer; }
8 };
10 template <class T>
11 struct MOZ_GLOBAL_CLASS TemplateClass {
12 T i;
15 void gobble(void *) { }
17 void misuseGlobalClass(int len) {
18 Global notValid; // expected-error {{variable of type 'Global' only valid as global}} expected-note {{value incorrectly allocated in an automatic variable}}
19 Global alsoNotValid[2]; // expected-error-re {{variable of type 'Global{{ ?}}[2]' only valid as global}} expected-note-re {{'Global{{ ?}}[2]' is a global type because it is an array of global type 'Global'}} expected-note {{value incorrectly allocated in an automatic variable}}
20 static Global valid;
21 static Global alsoValid[2];
23 gobble(&notValid);
24 gobble(&valid);
25 gobble(&alsoValid[0]);
27 gobble(new Global); // expected-error {{variable of type 'Global' only valid as global}} expected-note {{value incorrectly allocated on the heap}}
28 gobble(new Global[10]); // expected-error {{variable of type 'Global' only valid as global}} expected-note {{value incorrectly allocated on the heap}}
29 gobble(new TemplateClass<int>); // expected-error {{variable of type 'TemplateClass<int>' only valid as global}} expected-note {{value incorrectly allocated on the heap}}
30 gobble(len <= 5 ? &valid : new Global); // expected-error {{variable of type 'Global' only valid as global}} expected-note {{value incorrectly allocated on the heap}}
32 char buffer[sizeof(Global)];
33 gobble(new (buffer) Global);
36 Global valid;
37 struct RandomClass {
38 Global nonstaticMember; // expected-note {{'RandomClass' is a global type because member 'nonstaticMember' is a global type 'Global'}}
39 static Global staticMember;
41 struct MOZ_GLOBAL_CLASS RandomGlobalClass {
42 Global nonstaticMember;
43 static Global staticMember;
46 struct BadInherit : Global {}; // expected-note {{'BadInherit' is a global type because it inherits from a global type 'Global'}}
47 struct MOZ_GLOBAL_CLASS GoodInherit : Global {};
49 void misuseGlobalClassEvenMore(int len) {
50 BadInherit moreInvalid; // expected-error {{variable of type 'BadInherit' only valid as global}} expected-note {{value incorrectly allocated in an automatic variable}}
51 RandomClass evenMoreInvalid; // expected-error {{variable of type 'RandomClass' only valid as global}} expected-note {{value incorrectly allocated in an automatic variable}}