[IR] Handle large element size when calculating GEP indices
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 24 Sep 2021 18:42:47 +0000 (20:42 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 24 Sep 2021 20:20:20 +0000 (22:20 +0200)
commit5969e5743ae9cd17d08436a4b1139b8c4a24cc4d
tree5ddbbff5ddd3258879325f17eb5ea09e8ded51f9
parent531206310a27477f088f672f5e6fd688d77d9292
[IR] Handle large element size when calculating GEP indices

This is a fix for the issue reported at
https://reviews.llvm.org/D110043#3019942:
The ElementSize is a uint64_t and as such may be larger than the
index space, or be negative in the index space. This is UB, but
shouldn't cause assertion failures.

We address this by detecting whether the size is too large and
use a zero index in that case (which is always conservatively
correct).

Differential Revision: https://reviews.llvm.org/D110437
llvm/lib/IR/DataLayout.cpp
llvm/test/Transforms/GlobalOpt/large-element-size.ll [new file with mode: 0644]