Debian Codegraph @

clang/test/Sema/attr-enforce-tcb.cpp

raw
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2
3 #define PLACE_IN_TCB(NAME) [[clang::enforce_tcb(NAME)]]
4 #define PLACE_IN_TCB_LEAF(NAME) [[clang::enforce_tcb_leaf(NAME)]]
5
6 PLACE_IN_TCB("foo") void in_tcb_foo();
7 void not_in_tcb();
8
9 // Test behavior on classes and methods.
10 class C {
11 void bar();
12
13 PLACE_IN_TCB("foo")
14 void foo() {
15 // TODO: Figure out if we want to support methods at all.
16 // Does it even make sense to isolate individual methods into a TCB?
17 // Maybe a per-class attribute would make more sense?
18 bar(); // expected-warning{{calling 'bar' is a violation of trusted computing base 'foo'}}
19 }
20 };
21
22 // Test behavior on templates.
23 template <typename Ty>
24 PLACE_IN_TCB("foo")
25 void foo_never_instantiated() {
26 not_in_tcb(); // expected-warning{{calling 'not_in_tcb' is a violation of trusted computing base 'foo'}}
27 in_tcb_foo(); // no-warning
28 }
29
30 template <typename Ty>
31 PLACE_IN_TCB("foo")
32 void foo_specialized();
33
34 template<>
35 void foo_specialized<int>() {
36 not_in_tcb(); // expected-warning{{calling 'not_in_tcb' is a violation of trusted computing base 'foo'}}
37 in_tcb_foo(); // no-warning
38 }
39
40 PLACE_IN_TCB("foo")
41 void call_template_good() {
42 foo_specialized<int>(); // no-warning
43 }
44 PLACE_IN_TCB("bar")
45 void call_template_bad() {
46 foo_specialized<int>(); // expected-warning{{calling 'foo_specialized<int>' is a violation of trusted computing base 'bar'}}
47 }
48
49 template<typename Ty>
50 void foo_specialization_in_tcb();
51
52 template<>
53 PLACE_IN_TCB("foo")
54 void foo_specialization_in_tcb<int>() {
55 not_in_tcb(); //expected-warning{{calling 'not_in_tcb' is a violation of trusted computing base 'foo'}}
56 in_tcb_foo(); // no-warning
57 }
58
59 template<>
60 void foo_specialization_in_tcb<double>() {
61 not_in_tcb(); // no-warning
62 in_tcb_foo(); // no-warning
63 }
64
65 PLACE_IN_TCB("foo")
66 void call_specialization_in_tcb() {
67 foo_specialization_in_tcb<int>(); // no-warning
68 foo_specialization_in_tcb<long>(); // expected-warning{{calling 'foo_specialization_in_tcb<long>' is a violation of trusted computing base 'foo'}}
69 foo_specialization_in_tcb<double>(); // expected-warning{{'foo_specialization_in_tcb<double>' is a violation of trusted computing base 'foo'}}
70 }