[llvm] [llvm] Fix behavior of llvm.objectsize in presence of negative / large offset (PR #115504)
Harald van Dijk via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 13 11:21:48 PST 2024
================
@@ -580,6 +585,11 @@ bool llvm::getObjectSize(const Value *Ptr, uint64_t &Size, const DataLayout &DL,
if (!Data.bothKnown())
return false;
+ // We could compute an over-approximation in that situation, may be if
+ // Opts.EvalMode == Max, but let's bee conservative and bail out.
+ if (Data.Offset.isNegative())
+ return false;
----------------
hvdijk wrote:
> for which we currently return 3, and we used to return 1
Yes, that is a good example, thank you, I agree that 1 is a better result here. We have a phi with two incoming values, `%p.then` and `%p.else`.
For `%p.then`, the start of the object is 1 byte before the pointer, and the end of the object is 1 byte after the pointer.
For `%p.else`, the start of the object is 1 byte after the pointer, and the end of the object is 3 bytes after the pointer.
Since we are evaluating with `EvalMode==Max`, we merge these to conclude that we have a pointer *at most* 1 byte before the start of the object, and *at most* 3 bytes before the end of the object. This is all correct, and yet, the result is not the result we want. We no longer have enough information to return the result we want, and I am not sure we can fix that without a bigger re-working of the code without also returning incorrect results in other cases.
https://github.com/llvm/llvm-project/pull/115504
More information about the llvm-commits
mailing list