[ConstantFold] Fix incorrect inbounds inference for [0 x T] GEPs
authorNikita Popov <npopov@redhat.com>
Wed, 1 Feb 2023 13:34:38 +0000 (14:34 +0100)
committerNikita Popov <npopov@redhat.com>
Wed, 1 Feb 2023 14:14:11 +0000 (15:14 +0100)
commit78f88082de3627ea04501c83a08f52cf1e60b4f7
treea45a995048543c7473631f512ad0fb74caba424b
parent9c4591d7f3acaa00318900bdba4b4ba26c99c666
[ConstantFold] Fix incorrect inbounds inference for [0 x T] GEPs

Previously all indices into [0 x T] arrays were considered in
range, which resulted in us incorrectly inferring inbounds for
all GEPs of that form. We should not consider them in range here,
and instead bail out of the rewriting logic (which would divide
by zero).

Do continue to consider 0 always in range, to avoid changing
behavior for zero-index GEPs.
llvm/lib/IR/ConstantFold.cpp
llvm/test/CodeGen/WebAssembly/address-offsets.ll
llvm/test/Transforms/InstCombine/getelementptr.ll
llvm/test/Transforms/InstCombine/snprintf-2.ll
llvm/test/Transforms/InstCombine/snprintf-3.ll
llvm/test/Transforms/InstCombine/snprintf-4.ll