aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/Loads.cpp
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2024-07-29 11:28:03 -0700
committerGitHub <noreply@github.com>2024-07-29 11:28:03 -0700
commit6dba99e14f7e508a5028036b753fa7f84e846307 (patch)
treef423b0ffa0f16b7715cf3475971bd3ab6ee920e3 /llvm/lib/Analysis/Loads.cpp
parentf9e7cba122c2b636ddb975791aadf33c69f3f056 (diff)
downloadllvm-6dba99e14f7e508a5028036b753fa7f84e846307.zip
llvm-6dba99e14f7e508a5028036b753fa7f84e846307.tar.gz
llvm-6dba99e14f7e508a5028036b753fa7f84e846307.tar.bz2
[InstCombine][asan] Don't speculate loads before `select ptr` (#100773)
Even if memory is valid from `llvm` point of view, e.g. local alloca, sanitizers have API for user specific memory annotations. These annotations can be used to track size of the local object, e.g. inline vectors may prevent accesses beyond the current vector size. So valid programs should not access those parts of alloca before checking preconditions. Fixes #100639.
Diffstat (limited to 'llvm/lib/Analysis/Loads.cpp')
-rw-r--r--llvm/lib/Analysis/Loads.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp
index 1704f0d..a88469a 100644
--- a/llvm/lib/Analysis/Loads.cpp
+++ b/llvm/lib/Analysis/Loads.cpp
@@ -378,8 +378,12 @@ bool llvm::isSafeToLoadUnconditionally(Value *V, Align Alignment, const APInt &S
// If DT is not specified we can't make context-sensitive query
const Instruction* CtxI = DT ? ScanFrom : nullptr;
if (isDereferenceableAndAlignedPointer(V, Alignment, Size, DL, CtxI, AC, DT,
- TLI))
- return true;
+ TLI)) {
+ // With sanitizers `Dereferenceable` is not always enough for unconditional
+ // load.
+ if (!ScanFrom || !suppressSpeculativeLoadForSanitizers(*ScanFrom))
+ return true;
+ }
if (!ScanFrom)
return false;