[PATCH] D111654: [analyzer] Retrieve a value from list initialization of multi-dimensional array declaration.

Gabor Marton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 27 06:23:31 PDT 2021


martong added inline comments.


================
Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1706-1743
+  // Check offsets for being out of bounds.
   // C++20 [expr.add] 7.6.6.4 (excerpt):
   //   If P points to an array element i of an array object x with n
   //   elements, where i < 0 or i > n, the behavior is undefined.
   //   Dereferencing is not allowed on the "one past the last
   //   element", when i == n.
   // Example:
----------------
ASDenysPetrov wrote:
> martong wrote:
> > Perhaps this hunk could be in an individual implementation function?
> There are two //returns// inside the loop. That would not such easy to do a separate function for this.
> There are two //returns// inside the loop. That would not such easy to do a separate function for this.

I think you could return with an `Optional<SVal>` and then in the call site you could check if the optional is set.
`Optional<SVal> areOffsetsOutOfBounds(...)` ?

Then in the caller:
```
if (Optional<SVal> CheckResult = areOffsetsOutOfBounds(...))
  return *CheckResult;
```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111654/new/

https://reviews.llvm.org/D111654



More information about the cfe-commits mailing list