================
@@ -490,6 +491,47 @@ SVal SValBuilder::evalUnaryOp(ProgramStateRef state, 
UnaryOperator::Opcode opc,
   llvm_unreachable("Unexpected unary operator");
 }
 
+namespace {
+/// Iterate through to store to find the actual value this LazyCompoundVal
+/// corresponds to. Further reading is in LazyCompoundVal's docs.
+struct LazyHandler : public StoreManager::BindingsHandler {
+  nonloc::LazyCompoundVal l;
+  std::optional<SVal> &Ret;
+
+  LazyHandler(nonloc::LazyCompoundVal l, std::optional<SVal> &Ret)
+      : l(l), Ret(Ret) {}
+
+  virtual bool HandleBinding(StoreManager &SMgr, Store Store,
+                             const MemRegion *Region, SVal Val) override {
+    if (const MemRegion *MR = Val.getAsRegion()) {
+      if (MR->isSubRegionOf(l.getRegion()) && MR != l.getAsRegion()) {
+        Ret = Val;
+        return false;
+      }
+    }
+    return true;
+  }
+};
+} // namespace
+
+/// Find the actual value behind a LazyCompoundVal. May return none if the
+/// query fails, or only finds another LazyCompoundVal (e.g. circular
+/// reference).
+static std::optional<SVal> extractActualValueFrom(ProgramStateRef State,
+                                                  nonloc::LazyCompoundVal L) {
+  std::optional<SVal> Ret;
+  LazyHandler handler{L, Ret};
+  State->getStateManager().getStoreManager().iterBindings(State->getStore(),
----------------
NagyDonat wrote:

I checked the implementation of `iterBindings` and the other methods of 
`StoreManager` and I still think that `iterBindings` is not the right tool for 
this job and you should use `SVal StoreManager::getBinding(Store S, Loc L, 
QualType T)` instead.

I know that the documentation of `LazyCompoundVal` suggests using 
`iterBindings` and that those docs were blessed by several reviewers (including 
me), but that doesn't change the fact that there are other more practical 
methods _and_ `iterBindings` doesn't always provide a complete answer, because 
it only iterates over _direct_ bindings and skips the so-called default 
bindings.

https://github.com/llvm/llvm-project/pull/106982
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to