================
@@ -1726,20 +1725,27 @@ class BuildLockset : public 
ConstStmtVisitor<BuildLockset> {
   FactSet FSet;
   // The fact set for the function on exit.
   const FactSet &FunctionExitFSet;
+  // Use `LVarCtx` to keep track of the context at each program point, which
+  // will be used to translate DREs (by `SExprBuilder::translateDeclRefExpr`)
+  // to their canonical definitions:
   LocalVariableMap::Context LVarCtx;
   unsigned CtxIndex;
 
   // To update and adjust the context.
   void updateLocalVarMapCtx(const Stmt *S) {
-    if (S)
-      LVarCtx = Analyzer->LocalVarMap.getNextContext(CtxIndex, S, LVarCtx);
     if (!Analyzer->Handler.issueBetaWarnings())
       return;
     // The lookup closure needs to be reconstructed with the refreshed LVarCtx.
     Analyzer->SxBuilder.setLookupLocalVarExpr(
         [this, Ctx = LVarCtx](const NamedDecl *D) mutable -> const Expr * {
           return Analyzer->LocalVarMap.lookupExpr(D, Ctx);
         });
+    // The `setLookupLocalVarExpr` call above copies the context immediately
+    // before the statement `S`.  That is the context that should be used 
during
+    // visiting `S`.  Then we update `LVarCtx` to hold the context immediately
+    // after `S` for the next `Visit*` method.
+    if (S)
+      LVarCtx = Analyzer->LocalVarMap.getNextContext(CtxIndex, S, LVarCtx);
----------------
melver wrote:

This needs to happen with and without issueBetaWarnings(). So I think for the 
time being you need to just copy the LVarCtx before and then move it to the 
lambda.

https://github.com/llvm/llvm-project/pull/178952
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to