[clang] [analyzer] Don't copy field-by-field conjured LazyCompoundVals (2/4) (PR #115917)
DonĂ¡t Nagy via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 14 06:30:42 PST 2024
================
@@ -2609,9 +2611,42 @@ RegionBindingsRef RegionStoreManager::bindVector(RegionBindingsConstRef B,
return NewB;
}
+std::optional<SVal>
+RegionStoreManager::getUniqueDefaultBinding(Store S,
+ const MemRegion *BaseR) const {
+ assert(BaseR == BaseR->getBaseRegion() && "Expecting a base region");
+ const auto *Cluster = getRegionBindings(S).lookup(BaseR);
+ if (!Cluster || !llvm::hasSingleElement(*Cluster))
+ return std::nullopt;
+
+ const auto [Key, Value] = *Cluster->begin();
+ return Key.isDirect() ? std::optional<SVal>{} : Value;
----------------
NagyDonat wrote:
Ok, that's reasonable, I was just surprised at first glance. As a potential alternative I could also imagine an `if` instead of the ternary operator:
```suggestion
return std::nullopt;
if (const auto [Key, Value] = *Cluster->begin(); !Key.isDirect())
return Value;
return std::nullopt;
```
but the current implementation is also OK.
https://github.com/llvm/llvm-project/pull/115917
More information about the cfe-commits
mailing list