[clang] Thread Safety Analysis: Honor try-lock branches of a void conditional (PR #211973)

Jameson Nash via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 6 08:51:40 PST 2026


================
@@ -1691,10 +1691,15 @@ ThreadSafetyAnalyzer::getTerminatorTrylockCall(const CFGBlock *Block,
   assert(!Negate && "Must be called with Negate initialized to false");
 
   const Stmt *Cond = Block->getTerminatorCondition();
-  // We don't acquire try-locks on ?: branches, only when its result is used.
-  if (!Cond || isa<ConditionalOperator>(Block->getTerminatorStmt()))
+  if (!Cond)
     return {};
 
+  // We don't acquire try-locks on ?: branches, except when its result is used.
+  if (const auto *COp =
+          dyn_cast_if_present<ConditionalOperator>(Block->getTerminatorStmt()))
----------------
vtjnash wrote:

I honestly have looked at so much code since then, I don't remember. This PR was not long after 7581430722155 though, so I can't possibly have run into it though since that asserts non-null.

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


More information about the cfe-commits mailing list