[clang] Unknown array lvalue element (PR #133381)

DonĂ¡t Nagy via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 28 04:04:02 PDT 2025


================
@@ -511,13 +511,9 @@ SVal StoreManager::getLValueElement(QualType elementType, NonLoc Offset,
   // Only allow non-integer offsets if the base region has no offset itself.
   // FIXME: This is a somewhat arbitrary restriction. We should be using
   // SValBuilder here to add the two offsets without checking their types.
-  if (!isa<nonloc::ConcreteInt>(Offset)) {
-    if (isa<ElementRegion>(BaseRegion->StripCasts()))
-      return UnknownVal();
-
+  if (!isa<nonloc::ConcreteInt>(Offset))
----------------
NagyDonat wrote:

With this change you allow nested `ElementRegion` layers, while this old FIXME note suggests that in this case we should create a single `ElementRegion` where the index is the sum of the two symbolic values. However, that old suggestion could potentially lead to a more complex representation when two indexing operations use different element types (e.g. "shift this pointer value by two `int`s and then six `char`s) -- so I'm not sure that we should follow it.

Also note that now `security.ArrayBound` is smart enough to handle the nested `ElementRegion`s --  while earlier perhaps they would've been useless or even problematic.

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


More information about the cfe-commits mailing list