https://github.com/NagyDonat created https://github.com/llvm/llvm-project/pull/187020
The `CallEvent` has data members that store the `LocationContext` and the `CFGElementRef` (i.e. `CFGBlock` + index of statement within that block); but the method `getReturnValueUnderConstruction` ignored these and used the currently analyzed `LocationContext` and `CFGBlock` instead of them. This was logically incorrect and would have caused problems if the `CallEvent` was used later when the "currently analyzed" things are different. However, the lit tests do pass even if I assert that the currently analyzed `LocationContext` and `CFGBlock` is the same as the ones saved in the `CallEvent`, so I'm pretty sure that there was no actual problem caused by this bad logic and this commit won't cause functional changes. ---- I originally uploaded this change as a part of PR https://github.com/llvm/llvm-project/pull/186186, but following a reviewer suggestion, I created this separate PR instead. From 01e3b9f4eee8e2148777a3a6ac05add9cc5fb6fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= <[email protected]> Date: Mon, 16 Mar 2026 17:41:59 +0100 Subject: [PATCH] [NFCI][analyzer] Fix logic in CallEvent::getReturnValueUnderConstruction The `CallEvent` has data members that store the `LocationContext` and the `CFGElementRef` (i.e. `CFGBlock` + index of statement within that block); but the method `getReturnValueUnderConstruction` ignored these and used the currently analyzed `LocationContext` and `CFGBlock` instead of them. This was logically incorrect and would have caused problems if the `CallEvent` was used later when the "currently analyzed" things are different. However, the lit tests do pass even if I assert that the currently analyzed `LocationContext` and `CFGBlock` is the same as the ones saved in the `CallEvent`, so I'm pretty sure that there was no actual problem caused by this bad logic and this commit won't cause functional changes. --- clang/lib/StaticAnalyzer/Core/CallEvent.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp index 86ffd92cdf6f5..cd52083a278ae 100644 --- a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp +++ b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp @@ -562,13 +562,11 @@ std::optional<SVal> CallEvent::getReturnValueUnderConstruction() const { EvalCallOptions CallOpts; ExprEngine &Engine = getState()->getStateManager().getOwningEngine(); - // FIXME: This code assumes that the _current_ location context and block is - // the location and block where this `CallExpr` is called. For a more stable - // solution `Engine.getNumVisitedCurrent()` should be replaced with a call to - // `Engine.getNumVisited(<CallerLCtx>, <CallerBlock>)`. + unsigned NumVisitedCall = Engine.getNumVisited( + getLocationContext(), getCFGElementRef().getParent()); SVal RetVal = Engine.computeObjectUnderConstruction( - getOriginExpr(), getState(), Engine.getNumVisitedCurrent(), - getLocationContext(), CC, CallOpts); + getOriginExpr(), getState(), NumVisitedCall, getLocationContext(), CC, + CallOpts); return RetVal; } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
