annotate clang/test/Sema/attr-capabilities.c @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -Wthread-safety -verify %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 typedef int __attribute__((capability("role"))) ThreadRole;
anatofuz
parents:
diff changeset
4 struct __attribute__((shared_capability("mutex"))) Mutex {};
anatofuz
parents:
diff changeset
5 struct NotACapability {};
anatofuz
parents:
diff changeset
6
anatofuz
parents:
diff changeset
7 // Put capability attributes on unions
anatofuz
parents:
diff changeset
8 union __attribute__((capability("mutex"))) MutexUnion { int a; char* b; };
anatofuz
parents:
diff changeset
9 typedef union { int a; char* b; } __attribute__((capability("mutex"))) MutexUnion2;
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 // Test a different capability name
anatofuz
parents:
diff changeset
12 struct __attribute__((capability("custom"))) CustomName {};
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 int Test1 __attribute__((capability("test1"))); // expected-error {{'capability' attribute only applies to structs, unions, classes, and typedefs}}
anatofuz
parents:
diff changeset
15 int Test2 __attribute__((shared_capability("test2"))); // expected-error {{'shared_capability' attribute only applies to structs, unions, classes, and typedefs}}
anatofuz
parents:
diff changeset
16 int Test3 __attribute__((acquire_capability("test3"))); // expected-warning {{'acquire_capability' attribute only applies to functions}}
anatofuz
parents:
diff changeset
17 int Test4 __attribute__((try_acquire_capability("test4"))); // expected-error {{'try_acquire_capability' attribute only applies to functions}}
anatofuz
parents:
diff changeset
18 int Test5 __attribute__((release_capability("test5"))); // expected-warning {{'release_capability' attribute only applies to functions}}
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 struct __attribute__((capability(12))) Test3 {}; // expected-error {{'capability' attribute requires a string}}
anatofuz
parents:
diff changeset
21 struct __attribute__((shared_capability(Test2))) Test4 {}; // expected-error {{'shared_capability' attribute requires a string}}
anatofuz
parents:
diff changeset
22
anatofuz
parents:
diff changeset
23 struct __attribute__((capability)) Test5 {}; // expected-error {{'capability' attribute takes one argument}}
anatofuz
parents:
diff changeset
24 struct __attribute__((shared_capability("test1", 12))) Test6 {}; // expected-error {{'shared_capability' attribute takes one argument}}
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 struct NotACapability BadCapability;
anatofuz
parents:
diff changeset
27 ThreadRole GUI, Worker;
anatofuz
parents:
diff changeset
28 void Func1(void) __attribute__((requires_capability(GUI))) {}
anatofuz
parents:
diff changeset
29 void Func2(void) __attribute__((requires_shared_capability(Worker))) {}
anatofuz
parents:
diff changeset
30
anatofuz
parents:
diff changeset
31 void Func3(void) __attribute__((requires_capability)) {} // expected-error {{'requires_capability' attribute takes at least 1 argument}}
anatofuz
parents:
diff changeset
32 void Func4(void) __attribute__((requires_shared_capability)) {} // expected-error {{'requires_shared_capability' attribute takes at least 1 argument}}
anatofuz
parents:
diff changeset
33
anatofuz
parents:
diff changeset
34 void Func5(void) __attribute__((requires_capability(1))) {} // expected-warning {{'requires_capability' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'int'}}
anatofuz
parents:
diff changeset
35 void Func6(void) __attribute__((requires_shared_capability(BadCapability))) {} // expected-warning {{'requires_shared_capability' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'struct NotACapability'}}
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 void Func7(void) __attribute__((assert_capability(GUI))) {}
anatofuz
parents:
diff changeset
38 void Func8(void) __attribute__((assert_shared_capability(GUI))) {}
anatofuz
parents:
diff changeset
39
anatofuz
parents:
diff changeset
40 void Func9(void) __attribute__((assert_capability())) {} // expected-warning {{'assert_capability' attribute without capability arguments can only be applied to non-static methods of a class}}
anatofuz
parents:
diff changeset
41 void Func10(void) __attribute__((assert_shared_capability())) {} // expected-warning {{'assert_shared_capability' attribute without capability arguments can only be applied to non-static methods of a class}}
anatofuz
parents:
diff changeset
42
anatofuz
parents:
diff changeset
43 void Func11(void) __attribute__((acquire_capability(GUI))) {}
anatofuz
parents:
diff changeset
44 void Func12(void) __attribute__((acquire_shared_capability(GUI))) {}
anatofuz
parents:
diff changeset
45
anatofuz
parents:
diff changeset
46 void Func13(void) __attribute__((acquire_capability())) {} // expected-warning {{'acquire_capability' attribute without capability arguments can only be applied to non-static methods of a class}}
anatofuz
parents:
diff changeset
47 void Func14(void) __attribute__((acquire_shared_capability())) {} // expected-warning {{'acquire_shared_capability' attribute without capability arguments can only be applied to non-static methods of a class}}
anatofuz
parents:
diff changeset
48
anatofuz
parents:
diff changeset
49 void Func15(void) __attribute__((release_capability(GUI))) {}
anatofuz
parents:
diff changeset
50 void Func16(void) __attribute__((release_shared_capability(GUI))) {}
anatofuz
parents:
diff changeset
51 void Func17(void) __attribute__((release_generic_capability(GUI))) {}
anatofuz
parents:
diff changeset
52
anatofuz
parents:
diff changeset
53 void Func18(void) __attribute__((release_capability())) {} // expected-warning {{'release_capability' attribute without capability arguments can only be applied to non-static methods of a class}}
anatofuz
parents:
diff changeset
54 void Func19(void) __attribute__((release_shared_capability())) {} // expected-warning {{'release_shared_capability' attribute without capability arguments can only be applied to non-static methods of a class}}
anatofuz
parents:
diff changeset
55 void Func20(void) __attribute__((release_generic_capability())) {} // expected-warning {{'release_generic_capability' attribute without capability arguments can only be applied to non-static methods of a class}}
anatofuz
parents:
diff changeset
56
anatofuz
parents:
diff changeset
57 void Func21(void) __attribute__((try_acquire_capability(1))) {} // expected-warning {{'try_acquire_capability' attribute without capability arguments can only be applied to non-static methods of a class}}
anatofuz
parents:
diff changeset
58 void Func22(void) __attribute__((try_acquire_shared_capability(1))) {} // expected-warning {{'try_acquire_shared_capability' attribute without capability arguments can only be applied to non-static methods of a class}}
anatofuz
parents:
diff changeset
59
anatofuz
parents:
diff changeset
60 void Func23(void) __attribute__((try_acquire_capability(1, GUI))) {}
anatofuz
parents:
diff changeset
61 void Func24(void) __attribute__((try_acquire_shared_capability(1, GUI))) {}
anatofuz
parents:
diff changeset
62
anatofuz
parents:
diff changeset
63 void Func25(void) __attribute__((try_acquire_capability())) {} // expected-error {{'try_acquire_capability' attribute takes at least 1 argument}}
anatofuz
parents:
diff changeset
64 void Func26(void) __attribute__((try_acquire_shared_capability())) {} // expected-error {{'try_acquire_shared_capability' attribute takes at least 1 argument}}
anatofuz
parents:
diff changeset
65
anatofuz
parents:
diff changeset
66 // Test that boolean logic works with capability attributes
anatofuz
parents:
diff changeset
67 void Func27(void) __attribute__((requires_capability(!GUI)));
anatofuz
parents:
diff changeset
68 void Func28(void) __attribute__((requires_capability(GUI && Worker)));
anatofuz
parents:
diff changeset
69 void Func29(void) __attribute__((requires_capability(GUI || Worker)));
anatofuz
parents:
diff changeset
70 void Func30(void) __attribute__((requires_capability((Worker || Worker) && !GUI)));
anatofuz
parents:
diff changeset
71
anatofuz
parents:
diff changeset
72 int AlsoNotACapability;
anatofuz
parents:
diff changeset
73 void Func31(void) __attribute__((requires_capability(GUI && AlsoNotACapability))); // expected-warning {{'requires_capability' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'int'}}