[clang] [clang][ThreadSafety] Skip past implicit cast in `translateAttrExpr` (PR #92277)

via cfe-commits cfe-commits at lists.llvm.org
Wed May 15 08:05:33 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-analysis

@llvm/pr-subscribers-clang

Author: Antonio Frighetto (antoniofrighetto)

<details>
<summary>Changes</summary>

Ignore `ImplicitCastExpr` when building `AttrExp` for capability attribute diagnostics.

Fixes: https://github.com/llvm/llvm-project/issues/92118.

---
Full diff: https://github.com/llvm/llvm-project/pull/92277.diff


2 Files Affected:

- (modified) clang/lib/Analysis/ThreadSafetyCommon.cpp (+1-1) 
- (modified) clang/test/SemaCXX/warn-thread-safety-analysis.cpp (+1-1) 


``````````diff
diff --git a/clang/lib/Analysis/ThreadSafetyCommon.cpp b/clang/lib/Analysis/ThreadSafetyCommon.cpp
index 33f1f466df244..71de84f698e26 100644
--- a/clang/lib/Analysis/ThreadSafetyCommon.cpp
+++ b/clang/lib/Analysis/ThreadSafetyCommon.cpp
@@ -197,7 +197,7 @@ CapabilityExpr SExprBuilder::translateAttrExpr(const Expr *AttrExp,
   else if (const auto *UO = dyn_cast<UnaryOperator>(AttrExp)) {
     if (UO->getOpcode() == UO_LNot) {
       Neg = true;
-      AttrExp = UO->getSubExpr();
+      AttrExp = UO->getSubExpr()->IgnoreImplicit();
     }
   }
 
diff --git a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
index dfb966d3b5902..749d9e135d941 100644
--- a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -5341,7 +5341,7 @@ void dispatch_log(const char *msg) __attribute__((requires_capability(!FlightCon
 void dispatch_log2(const char *msg) __attribute__((requires_capability(Logger))) {}
 
 void flight_control_entry(void) __attribute__((requires_capability(FlightControl))) {
-  dispatch_log("wrong"); /* expected-warning {{cannot call function 'dispatch_log' while mutex 'FlightControl' is held}} */
+  dispatch_log("wrong"); /* expected-warning {{cannot call function 'dispatch_log' while role 'FlightControl' is held}} */
   dispatch_log2("also wrong"); /* expected-warning {{calling function 'dispatch_log2' requires holding role 'Logger' exclusively}} */
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/92277


More information about the cfe-commits mailing list