aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/MemoryBuiltins.cpp
diff options
context:
space:
mode:
authorserge-sans-paille <sguelton@mozilla.com>2024-12-20 12:16:49 +0000
committerGitHub <noreply@github.com>2024-12-20 12:16:49 +0000
commite4db3f0d97681a10a76e71465f1379801cd45f54 (patch)
tree525756364e9fa9dabbb455799300df5f86ece5cb /llvm/lib/Analysis/MemoryBuiltins.cpp
parent000febd0290698728abd9e23da6b27969c529177 (diff)
downloadllvm-e4db3f0d97681a10a76e71465f1379801cd45f54.zip
llvm-e4db3f0d97681a10a76e71465f1379801cd45f54.tar.gz
llvm-e4db3f0d97681a10a76e71465f1379801cd45f54.tar.bz2
[llvm] Bail out when meeting pointer with negative offset in approximated mode instead of … (#120424)
…generating empty location Fix the regression detected by https://github.com/llvm/llvm-test-suite/pull/188
Diffstat (limited to 'llvm/lib/Analysis/MemoryBuiltins.cpp')
-rw-r--r--llvm/lib/Analysis/MemoryBuiltins.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp
index 57b9799..6b7a3e1 100644
--- a/llvm/lib/Analysis/MemoryBuiltins.cpp
+++ b/llvm/lib/Analysis/MemoryBuiltins.cpp
@@ -838,11 +838,14 @@ OffsetSpan ObjectSizeOffsetVisitor::computeImpl(Value *V) {
// We end up pointing on a location that's outside of the original object.
if (ORT.knownBefore() && ORT.Before.isNegative()) {
- // This is UB, and we'd rather return an empty location then.
+ // This means that we *may* be accessing memory before the allocation.
+ // Conservatively return an unknown size.
+ //
+ // TODO: working with ranges instead of value would make it possible to take
+ // a better decision.
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());
+ return ObjectSizeOffsetVisitor::unknown();
}
// Otherwise it's fine, caller can handle negative offset.
}