Skip to content

Commit 419ef38

Browse files
committed
Revert "[attributes] Add a facility for enforcing a Trusted Computing Base."
This reverts commit c163aae. Doesn't compile on some bots (http://lab.llvm.org:8011/#/builders/98/builds/3387/steps/9/logs/stdio), breaks tests on bots where it does compile (http://45.33.8.238/linux/36843/step_7.txt).
1 parent eb0371e commit 419ef38

File tree

10 files changed

+0
-386
lines changed

10 files changed

+0
-386
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3653,19 +3653,3 @@ def Builtin : InheritableAttr {
36533653
let SemaHandler = 0;
36543654
let Documentation = [Undocumented];
36553655
}
3656-
3657-
def EnforceTCB : InheritableAttr {
3658-
let Spellings = [Clang<"enforce_tcb">];
3659-
let Subjects = SubjectList<[Function]>;
3660-
let Args = [StringArgument<"TCBName">];
3661-
let Documentation = [EnforceTCBDocs];
3662-
bit InheritEvenIfAlreadyPresent = 1;
3663-
}
3664-
3665-
def EnforceTCBLeaf : InheritableAttr {
3666-
let Spellings = [Clang<"enforce_tcb_leaf">];
3667-
let Subjects = SubjectList<[Function]>;
3668-
let Args = [StringArgument<"TCBName">];
3669-
let Documentation = [EnforceTCBLeafDocs];
3670-
bit InheritEvenIfAlreadyPresent = 1;
3671-
}

clang/include/clang/Basic/AttrDocs.td

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5725,28 +5725,3 @@ Attribute docs`_, and `the GCC Inline docs`_.
57255725
}];
57265726
let Heading = "always_inline, __force_inline";
57275727
}
5728-
5729-
def EnforceTCBDocs : Documentation {
5730-
let Category = DocCatFunction;
5731-
let Content = [{
5732-
The ``enforce_tcb`` attribute can be placed on functions to enforce that a
5733-
trusted compute base (TCB) does not call out of the TCB. This generates a
5734-
warning every time a function not marked with an ``enforce_tcb`` attribute is
5735-
called from a function with the ``enforce_tcb`` attribute. A function may be a
5736-
part of multiple TCBs. Invocations through function pointers are currently
5737-
not checked. Builtins are considered to a part of every TCB.
5738-
5739-
- ``enforce_tcb(Name)`` indicates that this function is a part of the TCB named ``Name``
5740-
}];
5741-
}
5742-
5743-
def EnforceTCBLeafDocs : Documentation {
5744-
let Category = DocCatFunction;
5745-
let Content = [{
5746-
The ``enforce_tcb_leaf`` attribute satisfies the requirement enforced by
5747-
``enforce_tcb`` for the marked function to be in the named TCB but does not
5748-
continue to check the functions called from within the leaf function.
5749-
5750-
- ``enforce_tcb_leaf(Name)`` indicates that this function is a part of the TCB named ``Name``
5751-
}];
5752-
}

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11116,11 +11116,4 @@ def err_probability_not_constant_float : Error<
1111611116
def err_probability_out_of_range : Error<
1111711117
"probability argument to __builtin_expect_with_probability is outside the "
1111811118
"range [0.0, 1.0]">;
11119-
11120-
// TCB warnings
11121-
def err_tcb_conflicting_attributes : Error<
11122-
"attributes '%0(\"%2\")' and '%1(\"%2\")' are mutually exclusive">;
11123-
def warn_tcb_enforcement_violation : Warning<
11124-
"calling %0 is a violation of trusted computing base '%1'">,
11125-
InGroup<DiagGroup<"tcb-enforcement">>;
1112611119
} // end of sema component.

clang/include/clang/Sema/Sema.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3210,9 +3210,6 @@ class Sema final {
32103210
Decl *D, const WebAssemblyImportNameAttr &AL);
32113211
WebAssemblyImportModuleAttr *mergeImportModuleAttr(
32123212
Decl *D, const WebAssemblyImportModuleAttr &AL);
3213-
EnforceTCBAttr *mergeEnforceTCBAttr(Decl *D, const EnforceTCBAttr &AL);
3214-
EnforceTCBLeafAttr *mergeEnforceTCBLeafAttr(Decl *D,
3215-
const EnforceTCBLeafAttr &AL);
32163213

32173214
void mergeDeclAttributes(NamedDecl *New, Decl *Old,
32183215
AvailabilityMergeKind AMK = AMK_Redeclaration);
@@ -12430,8 +12427,6 @@ class Sema final {
1243012427
/// attempts to add itself into the container
1243112428
void CheckObjCCircularContainer(ObjCMessageExpr *Message);
1243212429

12433-
void CheckTCBEnforcement(const CallExpr *TheCall, const FunctionDecl *Callee);
12434-
1243512430
void AnalyzeDeleteExprMismatch(const CXXDeleteExpr *DE);
1243612431
void AnalyzeDeleteExprMismatch(FieldDecl *Field, SourceLocation DeleteLoc,
1243712432
bool DeleteWasArrayForm);

clang/lib/Sema/SemaChecking.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
#include "llvm/ADT/SmallString.h"
7676
#include "llvm/ADT/SmallVector.h"
7777
#include "llvm/ADT/StringRef.h"
78-
#include "llvm/ADT/StringSet.h"
7978
#include "llvm/ADT/StringSwitch.h"
8079
#include "llvm/ADT/Triple.h"
8180
#include "llvm/Support/AtomicOrdering.h"
@@ -4570,8 +4569,6 @@ bool Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall,
45704569
if (!FnInfo)
45714570
return false;
45724571

4573-
CheckTCBEnforcement(TheCall, FDecl);
4574-
45754572
CheckAbsoluteValueFunction(TheCall, FDecl);
45764573
CheckMaxUnsignedZero(TheCall, FDecl);
45774574

@@ -16062,37 +16059,3 @@ ExprResult Sema::SemaBuiltinMatrixColumnMajorStore(CallExpr *TheCall,
1606216059

1606316060
return CallResult;
1606416061
}
16065-
16066-
/// \brief Enforce the bounds of a TCB
16067-
/// CheckTCBEnforcement - Enforces that every function in a named TCB only
16068-
/// directly calls other functions in the same TCB as marked by the enforce_tcb
16069-
/// and enforce_tcb_leaf attributes.
16070-
void Sema::CheckTCBEnforcement(const CallExpr *TheCall,
16071-
const FunctionDecl *Callee) {
16072-
const FunctionDecl *Caller = getCurFunctionDecl();
16073-
16074-
// Calls to builtins are not enforced.
16075-
if (!Caller || !Caller->hasAttr<EnforceTCBAttr>() ||
16076-
Callee->getBuiltinID() != 0)
16077-
return;
16078-
16079-
// Search through the enforce_tcb and enforce_tcb_leaf attributes to find
16080-
// all TCBs the callee is a part of.
16081-
llvm::StringSet<> CalleeTCBs;
16082-
for_each(Callee->specific_attrs<EnforceTCBAttr>(),
16083-
[&](const auto *A) { CalleeTCBs.insert(A->getTCBName()); });
16084-
for_each(Callee->specific_attrs<EnforceTCBLeafAttr>(),
16085-
[&](const auto *A) { CalleeTCBs.insert(A->getTCBName()); });
16086-
16087-
// Go through the TCBs the caller is a part of and emit warnings if Caller
16088-
// is in a TCB that the Callee is not.
16089-
for_each(
16090-
Caller->specific_attrs<EnforceTCBAttr>(),
16091-
[&](const auto *A) {
16092-
StringRef CallerTCB = A->getTCBName();
16093-
if (CalleeTCBs.count(CallerTCB) == 0) {
16094-
Diag(TheCall->getExprLoc(), diag::warn_tcb_enforcement_violation)
16095-
<< Callee << CallerTCB;
16096-
}
16097-
});
16098-
}

clang/lib/Sema/SemaDecl.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,10 +2612,6 @@ static bool mergeDeclAttribute(Sema &S, NamedDecl *D,
26122612
NewAttr = S.mergeImportModuleAttr(D, *IMA);
26132613
else if (const auto *INA = dyn_cast<WebAssemblyImportNameAttr>(Attr))
26142614
NewAttr = S.mergeImportNameAttr(D, *INA);
2615-
else if (const auto *TCBA = dyn_cast<EnforceTCBAttr>(Attr))
2616-
NewAttr = S.mergeEnforceTCBAttr(D, *TCBA);
2617-
else if (const auto *TCBLA = dyn_cast<EnforceTCBLeafAttr>(Attr))
2618-
NewAttr = S.mergeEnforceTCBLeafAttr(D, *TCBLA);
26192615
else if (Attr->shouldInheritEvenIfAlreadyPresent() || !DeclHasAttr(D, Attr))
26202616
NewAttr = cast<InheritableAttr>(Attr->clone(S.Context));
26212617

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -7517,75 +7517,6 @@ static void handleCFGuardAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
75177517
D->addAttr(::new (S.Context) CFGuardAttr(S.Context, AL, Arg));
75187518
}
75197519

7520-
7521-
template <typename AttrTy>
7522-
static const AttrTy *findEnforceTCBAttrByName(Decl *D, StringRef Name) {
7523-
auto Attrs = D->specific_attrs<AttrTy>();
7524-
auto I = llvm::find_if(Attrs,
7525-
[Name](const AttrTy *A) {
7526-
return A->getTCBName() == Name;
7527-
});
7528-
return I == Attrs.end() ? nullptr : *I;
7529-
}
7530-
7531-
template <typename AttrTy, typename ConflictingAttrTy>
7532-
static void handleEnforceTCBAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
7533-
StringRef Argument;
7534-
if (!S.checkStringLiteralArgumentAttr(AL, 0, Argument))
7535-
return;
7536-
7537-
// A function cannot be have both regular and leaf membership in the same TCB.
7538-
if (const ConflictingAttrTy *ConflictingAttr =
7539-
findEnforceTCBAttrByName<ConflictingAttrTy>(D, Argument)) {
7540-
// We could attach a note to the other attribute but in this case
7541-
// there's no need given how the two are very close to each other.
7542-
S.Diag(AL.getLoc(), diag::err_tcb_conflicting_attributes)
7543-
<< AL.getAttrName()->getName() << ConflictingAttr->getAttrName()->getName()
7544-
<< Argument;
7545-
7546-
// Error recovery: drop the non-leaf attribute so that to suppress
7547-
// all future warnings caused by erroneous attributes. The leaf attribute
7548-
// needs to be kept because it can only suppresses warnings, not cause them.
7549-
D->dropAttr<EnforceTCBAttr>();
7550-
return;
7551-
}
7552-
7553-
D->addAttr(AttrTy::Create(S.Context, Argument, AL));
7554-
}
7555-
7556-
template <typename AttrTy, typename ConflictingAttrTy>
7557-
static AttrTy *mergeEnforceTCBAttrImpl(Sema &S, Decl *D, const AttrTy &AL) {
7558-
// Check if the new redeclaration has different leaf-ness in the same TCB.
7559-
StringRef TCBName = AL.getTCBName();
7560-
if (const ConflictingAttrTy *ConflictingAttr =
7561-
findEnforceTCBAttrByName<ConflictingAttrTy>(D, TCBName)) {
7562-
S.Diag(ConflictingAttr->getLoc(), diag::err_tcb_conflicting_attributes)
7563-
<< ConflictingAttr->getAttrName()->getName()
7564-
<< AL.getAttrName()->getName() << TCBName;
7565-
7566-
// Add a note so that the user could easily find the conflicting attribute.
7567-
S.Diag(AL.getLoc(), diag::note_conflicting_attribute);
7568-
7569-
// More error recovery.
7570-
D->dropAttr<EnforceTCBAttr>();
7571-
return nullptr;
7572-
}
7573-
7574-
ASTContext &Context = S.getASTContext();
7575-
return ::new(Context) AttrTy(Context, AL, AL.getTCBName());
7576-
}
7577-
7578-
EnforceTCBAttr *Sema::mergeEnforceTCBAttr(Decl *D, const EnforceTCBAttr &AL) {
7579-
return mergeEnforceTCBAttrImpl<EnforceTCBAttr, EnforceTCBLeafAttr>(
7580-
*this, D, AL);
7581-
}
7582-
7583-
EnforceTCBLeafAttr *Sema::mergeEnforceTCBLeafAttr(
7584-
Decl *D, const EnforceTCBLeafAttr &AL) {
7585-
return mergeEnforceTCBAttrImpl<EnforceTCBLeafAttr, EnforceTCBAttr>(
7586-
*this, D, AL);
7587-
}
7588-
75897520
//===----------------------------------------------------------------------===//
75907521
// Top Level Sema Entry Points
75917522
//===----------------------------------------------------------------------===//
@@ -8289,14 +8220,6 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
82898220
case ParsedAttr::AT_UseHandle:
82908221
handleHandleAttr<UseHandleAttr>(S, D, AL);
82918222
break;
8292-
8293-
case ParsedAttr::AT_EnforceTCB:
8294-
handleEnforceTCBAttr<EnforceTCBAttr, EnforceTCBLeafAttr>(S, D, AL);
8295-
break;
8296-
8297-
case ParsedAttr::AT_EnforceTCBLeaf:
8298-
handleEnforceTCBAttr<EnforceTCBLeafAttr, EnforceTCBAttr>(S, D, AL);
8299-
break;
83008223
}
83018224
}
83028225

clang/test/Sema/attr-enforce-tcb-errors.cpp

Lines changed: 0 additions & 80 deletions
This file was deleted.

clang/test/Sema/attr-enforce-tcb.c

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)