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

Denys Petrov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 12 09:15:29 PDT 2021


ASDenysPetrov created this revision.
ASDenysPetrov added reviewers: NoQ, aaron.ballman, steakhal, martong, vsavchenko.
Herald added subscribers: manas, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
ASDenysPetrov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add support of multi-dimensional arrays in `RegionStoreManager::getBindingForElement`. Handle nested ElementRegion's getting offsets and checking for being in bounds. Get values from the nested initialization lists using obtained offsets.

Example:

  const int arr[3][2] = {{1, 2}, {3, 4}};
  arr[0][0];  // 1
  arr[0][1];  // 2
  arr[0][2];  // UB
  arr[1][0];  // 3
  arr[1][1];  // 4
  arr[1][-1]; // UB
  arr[2][0];  // 0
  arr[2][1];  // 0
  arr[-2][0]; // UB

P.S. this patch also includes D111542 <https://reviews.llvm.org/D111542> fix (without test cases, which I'll add separately).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111654

Files:
  clang/include/clang/AST/Type.h
  clang/lib/AST/Type.cpp
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/test/Analysis/initialization.c
  clang/test/Analysis/initialization.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111654.379073.patch
Type: text/x-patch
Size: 16560 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211012/1cf638f8/attachment-0001.bin>


More information about the cfe-commits mailing list