build/clang-plugin/tests/TestStackClass.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 #define MOZ_STACK_CLASS __attribute__((annotate("moz_stack_class")))
michael@0 2 #include <stddef.h>
michael@0 3
michael@0 4 struct MOZ_STACK_CLASS Stack {
michael@0 5 int i;
michael@0 6 void *operator new(size_t x) { return 0; }
michael@0 7 void *operator new(size_t blah, char *buffer) { return buffer; }
michael@0 8 };
michael@0 9
michael@0 10 template <class T>
michael@0 11 struct MOZ_STACK_CLASS TemplateClass {
michael@0 12 T i;
michael@0 13 };
michael@0 14
michael@0 15 void gobble(void *) { }
michael@0 16
michael@0 17 void misuseStackClass(int len) {
michael@0 18 Stack valid;
michael@0 19 Stack alsoValid[2];
michael@0 20 static Stack notValid; // expected-error {{variable of type 'Stack' only valid on the stack}}
michael@0 21 static Stack alsoNotValid[2]; // expected-error {{variable of type 'Stack [2]' only valid on the stack}}
michael@0 22
michael@0 23 gobble(&valid);
michael@0 24 gobble(&notValid);
michael@0 25 gobble(&alsoValid[0]);
michael@0 26
michael@0 27 gobble(new Stack); // expected-error {{variable of type 'Stack' only valid on the stack}}
michael@0 28 gobble(new Stack[10]); // expected-error {{variable of type 'Stack' only valid on the stack}}
michael@0 29 gobble(new TemplateClass<int>); // expected-error {{variable of type 'TemplateClass<int>' only valid on the stack}}
michael@0 30 gobble(len <= 5 ? &valid : new Stack); // expected-error {{variable of type 'Stack' only valid on the stack}}
michael@0 31
michael@0 32 char buffer[sizeof(Stack)];
michael@0 33 gobble(new (buffer) Stack);
michael@0 34 }
michael@0 35
michael@0 36 Stack notValid; // expected-error {{variable of type 'Stack' only valid on the stack}}
michael@0 37 struct RandomClass {
michael@0 38 Stack nonstaticMember; // expected-note {{'RandomClass' is a stack class because member 'nonstaticMember' is a stack class 'Stack'}}
michael@0 39 static Stack staticMember; // expected-error {{variable of type 'Stack' only valid on the stack}}
michael@0 40 };
michael@0 41 struct MOZ_STACK_CLASS RandomStackClass {
michael@0 42 Stack nonstaticMember;
michael@0 43 static Stack staticMember; // expected-error {{variable of type 'Stack' only valid on the stack}}
michael@0 44 };
michael@0 45
michael@0 46 struct BadInherit : Stack {}; // expected-note {{'BadInherit' is a stack class because it inherits from a stack class 'Stack'}}
michael@0 47 struct MOZ_STACK_CLASS GoodInherit : Stack {};
michael@0 48
michael@0 49 BadInherit moreInvalid; // expected-error {{variable of type 'BadInherit' only valid on the stack}}
michael@0 50 RandomClass evenMoreInvalid; // expected-error {{variable of type 'RandomClass' only valid on the stack}}

mercurial