[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 15:31: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:
I think your updated version still has the same potential problem. At the LLVM IR level, out of bounds pointers are not necessarily UB, it depends on whether a `getelemenptr` has the `inbounds` flag. In LLVM IR, it is possible to do the equivalent of `__builtin_object_size(array - 2 + 2, 0)` while keeping behaviour defined. To have this work, `computeImpl` needs to return the real `OffsetSpan` even for out of bounds pointers.
https://github.com/llvm/llvm-project/pull/115504
More information about the llvm-commits
mailing list