14 #ifndef LLVM_ANALYSIS_MEMORYBUILTINS_H 15 #define LLVM_ANALYSIS_MEMORYBUILTINS_H 35 class ConstantPointerNull;
37 class ExtractElementInst;
38 class ExtractValueInst;
51 class TargetLibraryInfo;
60 bool LookThroughBitCast =
false);
62 function_ref<
const TargetLibraryInfo &(Function &)> GetTLI,
63 bool LookThroughBitCast =
false);
68 bool LookThroughBitCast =
false);
73 bool LookThroughBitCast =
false);
75 function_ref<
const TargetLibraryInfo &(Function &)> GetTLI,
76 bool LookThroughBitCast =
false);
81 bool LookThroughBitCast =
false);
86 bool LookThroughBitCast =
false);
91 bool LookThroughBitCast =
false);
96 bool LookThroughBitCast =
false);
105 bool LookThroughBitCast =
false);
110 bool LookThroughBitCast =
false);
121 function_ref<
const TargetLibraryInfo &(Function &)> GetTLI);
149 bool LookThroughSExt =
false);
226 :
public InstVisitor<ObjectSizeOffsetVisitor, SizeOffsetType> {
247 return SizeOffset.first.getBitWidth() > 1;
251 return SizeOffset.second.getBitWidth() > 1;
255 return knownSize(SizeOffset) && knownOffset(SizeOffset);
277 bool CheckedZextOrTrunc(
APInt &I);
285 :
public InstVisitor<ObjectSizeOffsetEvaluator, SizeOffsetEvalType> {
287 using WeakEvalType = std::pair<WeakTrackingVH, WeakTrackingVH>;
306 return std::make_pair(
nullptr,
nullptr);
315 return SizeOffset.first;
319 return SizeOffset.second;
323 return knownSize(SizeOffset) || knownOffset(SizeOffset);
327 return knownSize(SizeOffset) && knownOffset(SizeOffset);
345 #endif // LLVM_ANALYSIS_MEMORYBUILTINS_H
bool getObjectSize(const Value *Ptr, uint64_t &Size, const DataLayout &DL, const TargetLibraryInfo *TLI, ObjectSizeOpts Opts={})
Compute the size of the object pointed by Ptr.
bool isAllocationFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates or reallocates memory (eith...
A parsed version of the target data layout string in and methods for querying it. ...
This class represents an incoming formal argument to a Function.
Base class for instruction visitors.
This class represents lattice values for constants.
static SizeOffsetEvalType unknown()
const CallInst * extractCallocCall(const Value *I, const TargetLibraryInfo *TLI)
extractCallocCall - Returns the corresponding CallInst if the instruction is a calloc call...
std::pair< Value *, Value * > SizeOffsetEvalType
static bool knownSize(const SizeOffsetType &SizeOffset)
bool NullIsUnknownSize
If this is true, null pointers in address space 0 will be treated as though they can't be evaluated...
This class represents a function call, abstracting a target machine's calling convention.
An efficient, type-erasing, non-owning reference to a callable.
bool RoundToAlign
Whether to round the result up to the alignment of allocas, byval arguments, and global variables...
bool isLibFreeFunction(const Function *F, const LibFunc TLIFn)
isLibFreeFunction - Returns true if the function is a builtin free()
An instruction for reading from memory.
bool isReallocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that reallocates memory (e...
const CallInst * isFreeCall(const Value *I, const TargetLibraryInfo *TLI)
isFreeCall - Returns non-null if the value is a call to the builtin free()
This class represents the LLVM 'select' instruction.
const CallInst * extractMallocCall(const Value *I, function_ref< const TargetLibraryInfo &(Function &)> GetTLI)
extractMallocCall - Returns the corresponding CallInst if the instruction is a malloc call...
'undef' values are things that do not have specified contents.
bool knownSize(SizeOffsetEvalType SizeOffset)
This file implements a class to represent arbitrary precision integral constant values and operations...
Value * lowerObjectSizeCall(IntrinsicInst *ObjectSize, const DataLayout &DL, const TargetLibraryInfo *TLI, bool MustSucceed)
Try to turn a call to @llvm.objectsize into an integer value of the given Type.
bool isNoAliasFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a function that returns a NoAlias pointer (including malloc/c...
Same as Min, except we pick the maximum size of all of the branches.
Evaluate all branches of an unknown condition.
Evaluate the size and offset of an object pointed to by a Value*.
bool isOpNewLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates memory and throws if an all...
Class to represent pointers.
Value * getMallocArraySize(CallInst *CI, const DataLayout &DL, const TargetLibraryInfo *TLI, bool LookThroughSExt=false)
getMallocArraySize - Returns the array size of a malloc call.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
Class to represent integer types.
This class represents a cast from an integer to a pointer.
std::pair< APInt, APInt > SizeOffsetType
PointerType * getMallocType(const CallInst *CI, const TargetLibraryInfo *TLI)
getMallocType - Returns the PointerType resulting from the malloc call.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Mode EvalMode
How we want to evaluate this object's size.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Evaluate the size and offset of an object pointed to by a Value* statically.
static bool knownOffset(const SizeOffsetType &SizeOffset)
Provides information about what library functions are available for the current target.
A constant pointer value that points to null.
Class for arbitrary precision integers.
Type * getMallocAllocatedType(const CallInst *CI, const TargetLibraryInfo *TLI)
getMallocAllocatedType - Returns the Type allocated by malloc call.
bool isMallocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates uninitialized memory (such ...
Fail to evaluate an unknown condition.
bool isMallocOrCallocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates memory similar to malloc or...
bool isCallocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates zero-filled memory (such as...
bool isAllocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates memory (either malloc...
bool knownOffset(SizeOffsetEvalType SizeOffset)
bool anyKnown(SizeOffsetEvalType SizeOffset)
static bool bothKnown(const SizeOffsetType &SizeOffset)
LLVM Value Representation.
Mode
Controls how we handle conditional statements with unknown conditions.
Various options to control the behavior of getObjectSize.
bool isStrdupLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates memory (strdup, strndup).
bool bothKnown(SizeOffsetEvalType SizeOffset)
A wrapper class for inspecting calls to intrinsic functions.
an instruction to allocate memory on the stack