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