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

Marco Elver via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 29 07:31:06 PDT 2025


================
@@ -241,7 +242,21 @@ CapabilityExpr SExprBuilder::translateAttrExpr(const Expr *AttrExp,
   return CapabilityExpr(E, AttrExp->getType(), Neg);
 }
 
-til::LiteralPtr *SExprBuilder::createVariable(const VarDecl *VD) {
+til::SExpr *SExprBuilder::translateVarDecl(const VarDecl *VD,
+                                           CallingContext *Ctx) {
+  assert(VD);
+  // Substitute local pointer variables with their initializers if they are
+  // explicitly const or never reassigned.
+  QualType Ty = VD->getType();
+  if (Ty->isPointerType() && VD->hasInit() && !isVariableReassigned(VD)) {
+    const Expr *Init = VD->getInit()->IgnoreParenImpCasts();
+    // Check for self-initialization to prevent infinite recursion.
----------------
melver wrote:

No, but it's legal C & C++ code, and if this isn't handled the compiler crashes (or never terminates) per the test I added for this.

I'm now handling it in isVariableReassigned - this looks more robust.

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


More information about the cfe-commits mailing list