[PATCH] D104285: [analyzer] Retrieve value by direct index from list initialization of constant array declaration.

Denys Petrov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 15 03:32:59 PDT 2021


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

We can use direct index to retrieve a value from multi-dimensional array relying on a fact that static constant array is a solid block of memory. Iterate through a list initialization using a raw index to get the value.

Example:

  const int arr[2][2] = {{1}, {3, 4}};
  const int *ptr = (int *)arr;
  ptr[0]; // 1
  ptr[1]; // 0
  ptr[2]; // 3
  ptr[3]; // 4

Fixes: https://bugs.llvm.org/show_bug.cgi?id=50604


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104285

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104285.352052.patch
Type: text/x-patch
Size: 12143 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210615/720f09a4/attachment-0001.bin>


More information about the cfe-commits mailing list