[PATCH] D86796: [Sema] Address-space sensitive index check for unbounded arrays
Bevin Hansson via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 4 05:43:06 PDT 2020
ebevhan added inline comments.
================
Comment at: clang/lib/Sema/SemaChecking.cpp:13981
+ bool overflow;
+ llvm::APInt product(index);
+ product += 1;
----------------
ebevhan wrote:
> chrish_ericsson_atx wrote:
> > ebevhan wrote:
> > > What if index is wider than AddrBits, but the active bits are fewer? Then you might miss out on triggering the overflow case in the multiplication.
> > Line 13984 checks for active bits of product being less than AddrBits, which is the same case (since product, by definition, has same width as index). So I think this is covered. If I've misunderstood, please re-ping.
> The overflow limit for _ovf is determined by the width of the APInt. If index is 32 bits wide but only has 14 bits active, and AddrBits is 16, then an umul_ovf might overflow past 16 bits but not for 32 bits since the product is the same width as the index. Then we won't detect the overflow.
Scratch this; I missed the second getActiveBits check. With that it should be fine.
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