[PATCH] D86796: [Sema] Address-space sensitive index check for unbounded arrays

Chris Hamilton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 2 10:13:02 PDT 2020


chrish_ericsson_atx marked 2 inline comments as done.
chrish_ericsson_atx added inline comments.


================
Comment at: clang/lib/Sema/SemaChecking.cpp:13989
+      MaxElems <<= AddrBits;
+      MaxElems /= ElemBytes;
+
----------------
ebevhan wrote:
> The size calculations here could probably be simplified by doing something like this:
> 
> * If getActiveBits of the index is greater than AddrBits, it's indexing outside
> * Construct an AddrBits-wide APInt containing the index value
> * Use umul_ovf with getTypeSizeInChars(ElementType); if that overflows, it's indexing outside
> 
Refactored as suggested.  I agree -- it's cleaner this way (eliminates the loop), and avoids a divide when no diag is required.  But it's still hard to read because of all the APInt bitwidth hijinks necessary to do the math without tripping asserts. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86796



More information about the cfe-commits mailing list