[PATCH] D91898: [attributes] Add a facility for defining and enforcing a Trusted Computing Base.

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 10 09:57:34 PST 2020


aaron.ballman added inline comments.


================
Comment at: clang/include/clang/Basic/Attr.td:3593
+def EnforceTCBLeaf : InheritableAttr {
+  let Spellings = [Clang<"enforce_tcb_leaf">];
+  let Subjects = SubjectList<[Function]>;
----------------
Are these two attributes mutually exclusive, or would it make sense for a function to use both of these at the same time?


================
Comment at: clang/lib/Sema/SemaChecking.cpp:16079-16084
+  for (const auto *Attr : Callee->specific_attrs<EnforceTCBAttr>()) {
+    CalleeTCBs.insert(Attr->getTCBName());
+  }
+  for (const auto *Attr : Callee->specific_attrs<EnforceTCBLeafAttr>()) {
+    CalleeTCBs.insert(Attr->getTCBName());
+  }
----------------
NoQ wrote:
> aaron.ballman wrote:
> > Pretty sure you can remove the manual loops here with something like this.
> `std::inserter` doesn't seem to work with `llvm::StringSet` but `llvm::for_each` works and seems to be more compact(?)
Weird about `std::inserter` but this is a good improvement as-is.


================
Comment at: clang/lib/Sema/SemaChecking.cpp:16090-16092
+    if (CalleeTCBs.count(CallerTCB) == 0) {
+      Diag(TheCall->getExprLoc(), diag::warn_tcb_enforcement_violation) << CallerTCB << Callee->getName();
+    }
----------------
NoQ wrote:
> aaron.ballman wrote:
> > 
> TIL that `<< Callee` adds quotes automatically. I should use clang diagnostic builders more often :)
Yeah -- the diagnostic engine knows how to format named things and will automatically insert quotes for you when given a named thing. Super handy, but not always super obvious.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91898/new/

https://reviews.llvm.org/D91898



More information about the cfe-commits mailing list