[clang] [clang][analyzer] Preserve symbolic-offset regions across pointer casts (PR #221213)
DonĂ¡t Nagy via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 22 12:50:55 PDT 2026
================
@@ -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
More information about the cfe-commits
mailing list