[clang] [analyzer] Fix VAListChecker for by-value va_list (PR #245289)

Benedek Kaibas via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 23 09:51:27 PST 2026


================
@@ -213,10 +289,35 @@ void VAListChecker::checkPreStmt(const VAArgExpr *VAA,
 void VAListChecker::checkDeadSymbols(SymbolReaper &SR,
                                      CheckerContext &C) const {
   ProgramStateRef State = C.getState();
+
+  // Cleanup runs before PreCall, and getVAListState may need these entries
+  // from any caller frame while the callee is analyzed.
+  llvm::SmallPtrSet<const MemRegion *, 2> CallArguments;
+  if (std::optional<PreStmtPurgeDeadSymbols> PP =
+          C.getLocation().getAs<PreStmtPurgeDeadSymbols>();
+      PP && CallEvent::isCallStmt(PP->getStmt())) {
+    CallEventRef<> Call =
+        State->getStateManager().getCallEventManager().getCall(
+            PP->getStmt(), State, C.getStackFrame(), C.getCFGElementRef());
+    if (Call) {
+      for (unsigned I = 0, E = Call->getNumArgs(); I != E; ++I) {
+        const Expr *ArgExpr = Call->getArgExpr(I);
+        if (!ArgExpr->getType()->isRecordType())
+          continue;
+        if (const MemRegion *Arg =
+                getVAListAsRegion(Call->getArgSVal(I), ArgExpr, C))
+          CallArguments.insert(Arg);
+      }
+    }
+  }
+
   VAListStateMapTy Tracked = State->get<VAListStateMap>();
   RegionVector Leaked;
   for (const auto &[Reg, S] : Tracked) {
-    if (SR.isLiveRegion(Reg))
+    const auto *VR = dyn_cast<VarRegion>(Reg);
----------------
benedekaibas wrote:

`Reg` comes as a key from `VAListStateMap`. Here you cast it as a `VarRegion`. In case we work with an `ElementRegion` that will be discarded. Getting `ElementRegion` however is possible if you look at `getVAListAsRegion`. So everything that is not `VarRegion` `NeededByCallee` returns false. Are you sure we only care about `VarRegion`s?

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


More information about the cfe-commits mailing list