71 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s2 3#define PLACE_IN_TCB(NAME) [[clang::enforce_tcb(NAME)]]4#define PLACE_IN_TCB_LEAF(NAME) [[clang::enforce_tcb_leaf(NAME)]]5 6PLACE_IN_TCB("foo") void in_tcb_foo();7void not_in_tcb();8 9// Test behavior on classes and methods.10class 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.23template <typename Ty>24PLACE_IN_TCB("foo")25void 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-warning28}29 30template <typename Ty>31PLACE_IN_TCB("foo")32void foo_specialized();33 34template<>35void 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-warning38}39 40PLACE_IN_TCB("foo")41void call_template_good() {42 foo_specialized<int>(); // no-warning43}44PLACE_IN_TCB("bar")45void call_template_bad() {46 foo_specialized<int>(); // expected-warning{{calling 'foo_specialized<int>' is a violation of trusted computing base 'bar'}}47}48 49template<typename Ty>50void foo_specialization_in_tcb();51 52template<>53PLACE_IN_TCB("foo")54void 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-warning57}58 59template<>60void foo_specialization_in_tcb<double>() {61 not_in_tcb(); // no-warning62 in_tcb_foo(); // no-warning63}64 65PLACE_IN_TCB("foo")66void call_specialization_in_tcb() {67 foo_specialization_in_tcb<int>(); // no-warning68 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}71