1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 
3 [[clang::enforce_tcb("oops")]] int wrong_subject_type; // expected-warning{{'enforce_tcb' attribute only applies to functions}}
4 
5 void no_arguments() __attribute__((enforce_tcb)); // expected-error{{'enforce_tcb' attribute takes one argument}}
6 
7 void too_many_arguments() __attribute__((enforce_tcb("test", 12))); // expected-error{{'enforce_tcb' attribute takes one argument}}
8 
9 void wrong_argument_type() __attribute__((enforce_tcb(12))); // expected-error{{'enforce_tcb' attribute requires a string}}
10 
11 [[clang::enforce_tcb_leaf("oops")]] int wrong_subject_type_leaf; // expected-warning{{'enforce_tcb_leaf' attribute only applies to functions}}
12 
13 void no_arguments_leaf() __attribute__((enforce_tcb_leaf)); // expected-error{{'enforce_tcb_leaf' attribute takes one argument}}
14 
15 void too_many_arguments_leaf() __attribute__((enforce_tcb_leaf("test", 12))); // expected-error{{'enforce_tcb_leaf' attribute takes one argument}}
16 void wrong_argument_type_leaf() __attribute__((enforce_tcb_leaf(12))); // expected-error{{'enforce_tcb_leaf' attribute requires a string}}
17 
18 void foo();
19 
20 __attribute__((enforce_tcb("x")))
21 __attribute__((enforce_tcb_leaf("x"))) // expected-error{{attributes 'enforce_tcb_leaf("x")' and 'enforce_tcb("x")' are mutually exclusive}}
both_tcb_and_tcb_leaf()22 void both_tcb_and_tcb_leaf() {
23   foo(); // no-warning
24 }
25 
26 __attribute__((enforce_tcb_leaf("x"))) // expected-note{{conflicting attribute is here}}
27 void both_tcb_and_tcb_leaf_on_separate_redeclarations();
28 __attribute__((enforce_tcb("x"))) // expected-error{{attributes 'enforce_tcb("x")' and 'enforce_tcb_leaf("x")' are mutually exclusive}}
both_tcb_and_tcb_leaf_on_separate_redeclarations()29 void both_tcb_and_tcb_leaf_on_separate_redeclarations() {
30   // Error recovery: no need to emit a warning when we didn't
31   // figure out our attributes to begin with.
32   foo(); // no-warning
33 }
34 
35 __attribute__((enforce_tcb_leaf("x")))
36 __attribute__((enforce_tcb("x"))) // expected-error{{attributes 'enforce_tcb("x")' and 'enforce_tcb_leaf("x")' are mutually exclusive}}
both_tcb_and_tcb_leaf_opposite_order()37 void both_tcb_and_tcb_leaf_opposite_order() {
38   foo(); // no-warning
39 }
40 
41 __attribute__((enforce_tcb("x"))) // expected-note{{conflicting attribute is here}}
42 void both_tcb_and_tcb_leaf_on_separate_redeclarations_opposite_order();
43 __attribute__((enforce_tcb_leaf("x"))) // expected-error{{attributes 'enforce_tcb_leaf("x")' and 'enforce_tcb("x")' are mutually exclusive}}
both_tcb_and_tcb_leaf_on_separate_redeclarations_opposite_order()44 void both_tcb_and_tcb_leaf_on_separate_redeclarations_opposite_order() {
45   foo(); // no-warning
46 }
47 
48 __attribute__((enforce_tcb("x")))
49 __attribute__((enforce_tcb_leaf("y"))) // no-error
both_tcb_and_tcb_leaf_but_different_identifiers()50 void both_tcb_and_tcb_leaf_but_different_identifiers() {
51   foo(); // expected-warning{{calling 'foo' is a violation of trusted computing base 'x'}}
52 }
53 __attribute__((enforce_tcb_leaf("x")))
54 __attribute__((enforce_tcb("y"))) // no-error
both_tcb_and_tcb_leaf_but_different_identifiers_opposite_order()55 void both_tcb_and_tcb_leaf_but_different_identifiers_opposite_order() {
56   foo(); // expected-warning{{calling 'foo' is a violation of trusted computing base 'y'}}
57 }
58 
59 __attribute__((enforce_tcb("x")))
60 void both_tcb_and_tcb_leaf_but_different_identifiers_on_separate_redeclarations();
61 __attribute__((enforce_tcb_leaf("y"))) // no-error
both_tcb_and_tcb_leaf_but_different_identifiers_on_separate_redeclarations()62 void both_tcb_and_tcb_leaf_but_different_identifiers_on_separate_redeclarations() {
63   foo(); // expected-warning{{calling 'foo' is a violation of trusted computing base 'x'}}
64 }
65 
66 __attribute__((enforce_tcb_leaf("x")))
67 void both_tcb_and_tcb_leaf_but_different_identifiers_on_separate_redeclarations_opposite_order();
68 __attribute__((enforce_tcb("y")))
both_tcb_and_tcb_leaf_but_different_identifiers_on_separate_redeclarations_opposite_order()69 void both_tcb_and_tcb_leaf_but_different_identifiers_on_separate_redeclarations_opposite_order() {
70   foo(); // expected-warning{{calling 'foo' is a violation of trusted computing base 'y'}}
71 }
72 
73 __attribute__((enforce_tcb("y")))
74 __attribute__((enforce_tcb("x")))
75 __attribute__((enforce_tcb_leaf("x"))) // expected-error{{attributes 'enforce_tcb_leaf("x")' and 'enforce_tcb("x")' are mutually exclusive}}
error_recovery_over_individual_tcbs()76 void error_recovery_over_individual_tcbs() {
77   // FIXME: Ideally this should warn. The conflict between attributes
78   // for TCB "x" shouldn't affect the warning about TCB "y".
79   foo(); // no-warning
80 }
81