aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/Loads.cpp
diff options
context:
space:
mode:
authorPhilip Reames <listmail@philipreames.com>2021-04-01 11:32:22 -0700
committerPhilip Reames <listmail@philipreames.com>2021-04-01 11:33:35 -0700
commitdb357891f0cf76253be3cd75f682b68544a411da (patch)
tree9dac1052d6a3d89fd1c78806e14406de6ed80873 /llvm/lib/Analysis/Loads.cpp
parent4391d764e153d17315a2822137e1ceca13b4c98d (diff)
downloadllvm-db357891f0cf76253be3cd75f682b68544a411da.zip
llvm-db357891f0cf76253be3cd75f682b68544a411da.tar.gz
llvm-db357891f0cf76253be3cd75f682b68544a411da.tar.bz2
Infer dereferenceability from malloc and friends
Hookup TLI when inferring object size from allocation calls. This allows the analysis to prove dereferenceability for known allocation functions (such as malloc/new/etc) in addition to those marked explicitly with the allocsize attribute. This is a follow up to 0129cd5 now that the bug fixed by e2c6621e6 is resolved. As noted in the test, this relies on being able to prove that there is no free between allocation and context (e.g. hoist location). At the moment, this is handled conservatively. I'm working strengthening out ability to reason about no-free regions separately. Differential Revision: https://reviews.llvm.org/D99737
Diffstat (limited to 'llvm/lib/Analysis/Loads.cpp')
-rw-r--r--llvm/lib/Analysis/Loads.cpp3
1 files changed, 1 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp
index 771c9e4..9a0211f 100644
--- a/llvm/lib/Analysis/Loads.cpp
+++ b/llvm/lib/Analysis/Loads.cpp
@@ -162,8 +162,7 @@ static bool isDereferenceableAndAlignedPointer(
Opts.RoundToAlign = false;
Opts.NullIsUnknownSize = true;
uint64_t ObjSize;
- // TODO: Plumb through TLI so that malloc routines and such work.
- if (getObjectSize(V, ObjSize, DL, nullptr, Opts)) {
+ if (getObjectSize(V, ObjSize, DL, TLI, Opts)) {
APInt KnownDerefBytes(Size.getBitWidth(), ObjSize);
if (KnownDerefBytes.getBoolValue() && KnownDerefBytes.uge(Size) &&
isKnownNonZero(V, DL, 0, nullptr, CtxI, DT) && !V->canBeFreed()) {