71 lines · c
1// RUN: %clang_cc1 -fsyntax-only -verify %s2 3#define PLACE_IN_TCB(NAME) __attribute__ ((enforce_tcb(NAME)))4#define PLACE_IN_TCB_LEAF(NAME) __attribute__ ((enforce_tcb_leaf(NAME)))5 6void foo1 (void) PLACE_IN_TCB("bar");7void foo2 (void) PLACE_IN_TCB("bar");8void foo3 (void); // not in any TCB9void foo4 (void) PLACE_IN_TCB("bar2");10void foo5 (void) PLACE_IN_TCB_LEAF("bar");11void foo6 (void) PLACE_IN_TCB("bar2") PLACE_IN_TCB("bar");12void foo7 (void) PLACE_IN_TCB("bar3");13void foo8 (void) PLACE_IN_TCB("bar") PLACE_IN_TCB("bar2");14void foo9 (void);15 16void foo1(void) {17 foo2(); // OK - function in same TCB18 foo3(); // expected-warning {{calling 'foo3' is a violation of trusted computing base 'bar'}}19 foo4(); // expected-warning {{calling 'foo4' is a violation of trusted computing base 'bar'}}20 foo5(); // OK - in leaf node21 foo6(); // OK - in multiple TCBs, one of which is the same22 foo7(); // expected-warning {{calling 'foo7' is a violation of trusted computing base 'bar'}}23 (void) __builtin_clz(5); // OK - builtins are excluded24}25 26// Normal use without any attributes works27void foo3(void) {28 foo9(); // no-warning29}30 31void foo5(void) {32 // all calls should be okay, function in TCB leaf33 foo2(); // no-warning34 foo3(); // no-warning35 foo4(); // no-warning36}37 38void foo6(void) {39 foo1(); // expected-warning {{calling 'foo1' is a violation of trusted computing base 'bar2'}}40 foo4(); // expected-warning {{calling 'foo4' is a violation of trusted computing base 'bar'}}41 foo8(); // no-warning42 foo7(); // #143 // expected-warning@#1 {{calling 'foo7' is a violation of trusted computing base 'bar2'}}44 // expected-warning@#1 {{calling 'foo7' is a violation of trusted computing base 'bar'}}45}46 47// Ensure that attribute merging works as expected across redeclarations.48void foo10(void) PLACE_IN_TCB("bar");49void foo10(void) PLACE_IN_TCB("bar2");50void foo10(void) PLACE_IN_TCB("bar3");51void foo10(void) {52 foo1(); // #253 // expected-warning@#2 {{calling 'foo1' is a violation of trusted computing base 'bar2'}}54 // expected-warning@#2 {{calling 'foo1' is a violation of trusted computing base 'bar3'}}55 foo3(); // #356 // expected-warning@#3 {{calling 'foo3' is a violation of trusted computing base 'bar'}}57 // expected-warning@#3 {{calling 'foo3' is a violation of trusted computing base 'bar2'}}58 // expected-warning@#3 {{calling 'foo3' is a violation of trusted computing base 'bar3'}}59 foo4(); // #460 // expected-warning@#4 {{calling 'foo4' is a violation of trusted computing base 'bar'}}61 // expected-warning@#4 {{calling 'foo4' is a violation of trusted computing base 'bar3'}}62 foo7(); // #563 // expected-warning@#5 {{calling 'foo7' is a violation of trusted computing base 'bar'}}64 // expected-warning@#5 {{calling 'foo7' is a violation of trusted computing base 'bar2'}}65}66 67int foo11();68void foo12() PLACE_IN_TCB("bar4"){69 __typeof(foo11()) x; // OK - the call isn't actually evaluated.70}71