[clang] Thread Safety Analysis: Basic capability alias-analysis (PR #142955)

Marco Elver via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 2 16:27:25 PDT 2025


================
@@ -1012,6 +1030,107 @@ void SExprBuilder::exitCFG(const CFGBlock *Last) {
   IncompleteArgs.clear();
 }
 
+bool SExprBuilder::isVariableReassigned(const VarDecl *VD) {
+  // Note: The search is performed lazily per-variable and result is cached. An
+  // alternative would have been to eagerly create a set of all reassigned
+  // variables, but that would consume significantly more memory. The number of
----------------
melver wrote:

I think I solved this one (and a few more cases, too). We cannot rely on the LocalVarMap if its results may be imprecise (complex merge points exist in CFG) - and that's a fundamental limitation unless we dare to try and analyze loops.

So we have to employ a hybrid strategy: do the simple thing of resolving initializers if a variable is never reassigned / const, and otherwise attempt to use the LocalVarMap if its results are "precise"; if none of these work, fallback to no alias resolution.

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


More information about the cfe-commits mailing list