[clang] [analyzer] Resolve initializers for fields of struct array elements i… (PR #189361)

Endre Fülöp via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 31 06:01:14 PDT 2026


================
@@ -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())) {
----------------
gamesh411 wrote:

So in a sense I was mislead by `IsMainAnalysis`, but at the same time the first implementation (which is still the current one as of now) is correct in this sense, that non-const globals inside main are modeled as unknowns.

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


More information about the cfe-commits mailing list