diff options
author | serge-sans-paille <sguelton@mozilla.com> | 2024-11-23 07:38:37 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-23 07:38:37 +0000 |
commit | 19ddafafdf131aed40abbdaf5af1fb7b59c1e8ac (patch) | |
tree | 2dd54530d4d4b8bdd98bb916e52745e257c52ae8 /llvm/lib/Analysis/MemoryBuiltins.cpp | |
parent | 68f7b075c07197803625431ba92c337af7470c85 (diff) | |
download | llvm-19ddafafdf131aed40abbdaf5af1fb7b59c1e8ac.zip llvm-19ddafafdf131aed40abbdaf5af1fb7b59c1e8ac.tar.gz llvm-19ddafafdf131aed40abbdaf5af1fb7b59c1e8ac.tar.bz2 |
[llvm] Fix ObjectSizeOffsetVisitor behavior in exact mode upon negati… (#116955)
…ve offset
In Exact mode, the approximation of returning (0,0) is invalid. It only
holds in min/max mode.
Diffstat (limited to 'llvm/lib/Analysis/MemoryBuiltins.cpp')
-rw-r--r-- | llvm/lib/Analysis/MemoryBuiltins.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp index cd8594d..4028d5f 100644 --- a/llvm/lib/Analysis/MemoryBuiltins.cpp +++ b/llvm/lib/Analysis/MemoryBuiltins.cpp @@ -565,10 +565,7 @@ static APInt getSizeWithOverflow(const SizeOffsetAPInt &Data) { APInt Size = Data.Size; APInt Offset = Data.Offset; - assert(!Offset.isNegative() && - "size for a pointer before the allocated object is ambiguous"); - - if (Size.ult(Offset)) + if (Offset.isNegative() || Size.ult(Offset)) return APInt::getZero(Size.getBitWidth()); return Size - Offset; @@ -756,10 +753,14 @@ OffsetSpan ObjectSizeOffsetVisitor::computeImpl(Value *V) { } // We end up pointing on a location that's outside of the original object. - // This is UB, and we'd rather return an empty location then. if (ORT.knownBefore() && ORT.Before.isNegative()) { - ORT.Before = APInt::getZero(ORT.Before.getBitWidth()); - ORT.After = APInt::getZero(ORT.Before.getBitWidth()); + // This is UB, and we'd rather return an empty location then. + if (Options.EvalMode == ObjectSizeOpts::Mode::Min || + Options.EvalMode == ObjectSizeOpts::Mode::Max) { + ORT.Before = APInt::getZero(ORT.Before.getBitWidth()); + ORT.After = APInt::getZero(ORT.Before.getBitWidth()); + } + // Otherwise it's fine, caller can handle negative offset. } return ORT; } |