llvm-project
dd5682b1 - [ConstantFolding] Compute GEP offsets in the index width (#235838)

Commit
35 days ago
[ConstantFolding] Compute GEP offsets in the index width (#235838) SymbolicallyEvaluateGEP rewrites a GEP with constant indices as a base pointer plus a byte offset, absorbing the GEPs it is based on. It computed each offset with DataLayout::getIndexedOffsetInType, which returns an int64_t, and then extended the result to the index width. That is wrong when the index type is wider than 64 bits, e.g. with p:128:128: * an index that doesn't fit int64_t hits the assertion in APInt::getSExtValue, and is truncated in builds without assertions; * indices that each fit int64_t but whose sum doesn't are silently wrapped, even with assertions. Use GEPOperator::accumulateConstantOffset, which accumulates in an APInt of the index width, and don't fold if it fails to compute the offset.
Author
Parents
Loading