================
@@ -175,10 +175,13 @@ std::optional<const MemRegion *> 
StoreManager::castRegion(const MemRegion *R,
       const RegionRawOffset &rawOff = elementR->getAsArrayOffset();
       const MemRegion *baseR = rawOff.getRegion();
 
-      // If we cannot compute a raw offset, throw up our hands and return
-      // a NULL MemRegion*.
-      if (!baseR)
-        return std::nullopt;
+      if (!baseR) {
+        const MemRegion *uncastedR = elementR->StripCasts(false);
+        if (IsSameRegionType(uncastedR, CanonPointeeTy))
+          return uncastedR;
+
+        return MakeElementRegion(cast<SubRegion>(uncastedR), PointeeTy);
+      }
----------------
NagyDonat wrote:

At first glance I agree with the suggestion that the canonicalization logic 
probably "belongs to"  `getElementRegion` (the primary factory function that 
IIUC participates in the creation of all element regions) instead of the Store.

By the way, thanks for working on this deficiency of the analyzer! I vaguely 
recall that I have seen this "throw up our hands" logic and was annoyed by it, 
but I didn't have time for a deeper investigation and gradually forgot about 
it. It would be very nice to have a better logic here :smile:

https://github.com/llvm/llvm-project/pull/221213
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to