================
@@ -2145,6 +2145,46 @@ SVal
RegionStoreManager::getBindingForField(RegionBindingsConstRef B,
}
}
+ // In case of array of structs, the super-region is not directly a VarRegion,
+ // instead there is another layer of ElementRegion in between them, i.e.:
+ // FieldRegion(ElementRegion(VarRegion)).
+ if (const auto *ER = dyn_cast<ElementRegion>(superR)) {
+ if (const auto *VR = dyn_cast<VarRegion>(ER->getSuperRegion())) {
+ const VarDecl *VD = VR->getDecl();
+ QualType ArrayTy = VD->getType();
+ unsigned FieldIdx = FD->getFieldIndex();
+
+ if (ArrayTy.isConstQualified() || Ty.isConstQualified() ||
+ (B.isMainAnalysis() && VD->hasGlobalStorage())) {
+ if (const Expr *Init = VD->getAnyInitializer())
+ if (const auto *InitList = dyn_cast<InitListExpr>(Init))
+ if (const auto CI = ER->getIndex().getAs<nonloc::ConcreteInt>()) {
+ uint64_t ElemIdx = CI->getValue()->getZExtValue();
----------------
steakhal wrote:
I didn't check what this does, but just looking at how the nesting gets out of
control, I'm considering alternatives. I suspect that the `getBindingForField`
is already quite large so this could be a great opportunity to implement this
niche case outside of that.
https://github.com/llvm/llvm-project/pull/189361
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits