[clang] bb209ce - [-Wtcb-enforcement] Disable on unevaluated code.

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 13 14:36:59 PDT 2023


Author: Artem Dergachev
Date: 2023-06-13T14:36:51-07:00
New Revision: bb209ce138e71f2fd646b7f0f865f957336c67e9

URL: https://github.com/llvm/llvm-project/commit/bb209ce138e71f2fd646b7f0f865f957336c67e9
DIFF: https://github.com/llvm/llvm-project/commit/bb209ce138e71f2fd646b7f0f865f957336c67e9.diff

LOG: [-Wtcb-enforcement] Disable on unevaluated code.

It doesn't make sense for this warning to warn about things
that don't impact runtime behavior.

Added: 
    

Modified: 
    clang/lib/Sema/SemaChecking.cpp
    clang/test/Sema/attr-enforce-tcb.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index d5c046377632f..96f8d49b80f2c 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -18536,6 +18536,10 @@ bool Sema::BuiltinWasmTableCopy(CallExpr *TheCall) {
 /// and enforce_tcb_leaf attributes.
 void Sema::CheckTCBEnforcement(const SourceLocation CallExprLoc,
                                const NamedDecl *Callee) {
+  // This warning does not make sense in code that has no runtime behavior.
+  if (isUnevaluatedContext())
+    return;
+
   const NamedDecl *Caller = getCurFunctionOrMethodDecl();
 
   if (!Caller || !Caller->hasAttr<EnforceTCBAttr>())

diff  --git a/clang/test/Sema/attr-enforce-tcb.c b/clang/test/Sema/attr-enforce-tcb.c
index 650c03c56e639..8e352cd7c1013 100644
--- a/clang/test/Sema/attr-enforce-tcb.c
+++ b/clang/test/Sema/attr-enforce-tcb.c
@@ -63,3 +63,8 @@ void foo10(void) {
     // expected-warning@#5 {{calling 'foo7' is a violation of trusted computing base 'bar'}}
     // expected-warning@#5 {{calling 'foo7' is a violation of trusted computing base 'bar2'}}
 }
+
+int foo11();
+void foo12() PLACE_IN_TCB("bar4"){
+  __typeof(foo11()) x; // OK - the call isn't actually evaluated.
+}


        


More information about the cfe-commits mailing list