[PATCH] D32188: [MemoryBuiltins] Add isMallocOrCallocLikeFn so BasicAA can check for both at the same time
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 18 14:56:47 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL300608: [MemoryBuiltins] Add isMallocOrCallocLikeFn so BasicAA can check for both at… (authored by ctopper).
Changed prior to commit:
https://reviews.llvm.org/D32188?vs=95621&id=95640#toc
Repository:
rL LLVM
https://reviews.llvm.org/D32188
Files:
llvm/trunk/include/llvm/Analysis/MemoryBuiltins.h
llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
llvm/trunk/lib/Analysis/CFLGraph.h
llvm/trunk/lib/Analysis/MemoryBuiltins.cpp
Index: llvm/trunk/include/llvm/Analysis/MemoryBuiltins.h
===================================================================
--- llvm/trunk/include/llvm/Analysis/MemoryBuiltins.h
+++ llvm/trunk/include/llvm/Analysis/MemoryBuiltins.h
@@ -54,6 +54,11 @@
bool LookThroughBitCast = false);
/// \brief Tests if a value is a call or invoke to a library function that
+/// allocates memory similar to malloc or calloc.
+bool isMallocOrCallocLikeFn(const Value *V, const TargetLibraryInfo *TLI,
+ bool LookThroughBitCast = false);
+
+/// \brief Tests if a value is a call or invoke to a library function that
/// allocates memory (either malloc, calloc, or strdup like).
bool isAllocLikeFn(const Value *V, const TargetLibraryInfo *TLI,
bool LookThroughBitCast = false);
Index: llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
===================================================================
--- llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
+++ llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
@@ -808,7 +808,7 @@
// well. Or alternatively, replace all of this with inaccessiblememonly once
// that's implemented fully.
auto *Inst = CS.getInstruction();
- if (isMallocLikeFn(Inst, &TLI) || isCallocLikeFn(Inst, &TLI)) {
+ if (isMallocOrCallocLikeFn(Inst, &TLI)) {
// Be conservative if the accessed pointer may alias the allocation -
// fallback to the generic handling below.
if (getBestAAResults().alias(MemoryLocation(Inst), Loc) == NoAlias)
Index: llvm/trunk/lib/Analysis/CFLGraph.h
===================================================================
--- llvm/trunk/lib/Analysis/CFLGraph.h
+++ llvm/trunk/lib/Analysis/CFLGraph.h
@@ -400,8 +400,7 @@
// TODO: address other common library functions such as realloc(),
// strdup(),
// etc.
- if (isMallocLikeFn(Inst, &TLI) || isCallocLikeFn(Inst, &TLI) ||
- isFreeCall(Inst, &TLI))
+ if (isMallocOrCallocLikeFn(Inst, &TLI) || isFreeCall(Inst, &TLI))
return;
// TODO: Add support for noalias args/all the other fun function
Index: llvm/trunk/lib/Analysis/MemoryBuiltins.cpp
===================================================================
--- llvm/trunk/lib/Analysis/MemoryBuiltins.cpp
+++ llvm/trunk/lib/Analysis/MemoryBuiltins.cpp
@@ -37,6 +37,7 @@
CallocLike = 1<<2, // allocates + bzero
ReallocLike = 1<<3, // reallocates
StrDupLike = 1<<4,
+ MallocOrCallocLike = MallocLike | CallocLike,
AllocLike = MallocLike | CallocLike | StrDupLike,
AnyAlloc = AllocLike | ReallocLike
};
@@ -220,6 +221,14 @@
}
/// \brief Tests if a value is a call or invoke to a library function that
+/// allocates memory similiar to malloc or calloc.
+bool llvm::isMallocOrCallocLikeFn(const Value *V, const TargetLibraryInfo *TLI,
+ bool LookThroughBitCast) {
+ return getAllocationData(V, MallocOrCallocLike, TLI,
+ LookThroughBitCast).hasValue();
+}
+
+/// \brief Tests if a value is a call or invoke to a library function that
/// allocates memory (either malloc, calloc, or strdup like).
bool llvm::isAllocLikeFn(const Value *V, const TargetLibraryInfo *TLI,
bool LookThroughBitCast) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32188.95640.patch
Type: text/x-patch
Size: 3326 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170418/db3f8277/attachment.bin>
More information about the llvm-commits
mailing list