LLVM  13.0.0git
MemoryBuiltins.h
Go to the documentation of this file.
1 //==- llvm/Analysis/MemoryBuiltins.h - Calls to memory builtins --*- C++ -*-==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This family of functions identifies calls to builtin functions that allocate
10 // or free memory.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_ANALYSIS_MEMORYBUILTINS_H
15 #define LLVM_ANALYSIS_MEMORYBUILTINS_H
16 
17 #include "llvm/ADT/APInt.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/SmallPtrSet.h"
22 #include "llvm/IR/IRBuilder.h"
23 #include "llvm/IR/InstVisitor.h"
24 #include "llvm/IR/ValueHandle.h"
25 #include <cstdint>
26 #include <utility>
27 
28 namespace llvm {
29 
30 class AllocaInst;
31 class Argument;
32 class CallInst;
33 class ConstantInt;
34 class ConstantPointerNull;
35 class DataLayout;
36 class ExtractElementInst;
37 class ExtractValueInst;
38 class GEPOperator;
39 class GlobalAlias;
40 class GlobalVariable;
41 class Instruction;
42 class IntegerType;
43 class IntrinsicInst;
44 class IntToPtrInst;
45 class LLVMContext;
46 class LoadInst;
47 class PHINode;
48 class PointerType;
49 class SelectInst;
50 class Type;
51 class UndefValue;
52 class Value;
53 
54 /// Tests if a value is a call or invoke to a library function that
55 /// allocates or reallocates memory (either malloc, calloc, realloc, or strdup
56 /// like).
57 bool isAllocationFn(const Value *V, const TargetLibraryInfo *TLI,
58  bool LookThroughBitCast = false);
59 bool isAllocationFn(const Value *V,
60  function_ref<const TargetLibraryInfo &(Function &)> GetTLI,
61  bool LookThroughBitCast = false);
62 
63 /// Tests if a value is a call or invoke to a function that returns a
64 /// NoAlias pointer (including malloc/calloc/realloc/strdup-like functions).
65 bool isNoAliasFn(const Value *V, const TargetLibraryInfo *TLI,
66  bool LookThroughBitCast = false);
67 
68 /// Tests if a value is a call or invoke to a library function that
69 /// allocates uninitialized memory (such as malloc).
70 bool isMallocLikeFn(const Value *V, const TargetLibraryInfo *TLI,
71  bool LookThroughBitCast = false);
72 bool isMallocLikeFn(const Value *V,
73  function_ref<const TargetLibraryInfo &(Function &)> GetTLI,
74  bool LookThroughBitCast = false);
75 
76 /// Tests if a value is a call or invoke to a library function that
77 /// allocates uninitialized memory with alignment (such as aligned_alloc).
78 bool isAlignedAllocLikeFn(const Value *V, const TargetLibraryInfo *TLI,
79  bool LookThroughBitCast = false);
81  const Value *V, function_ref<const TargetLibraryInfo &(Function &)> GetTLI,
82  bool LookThroughBitCast = false);
83 
84 /// Tests if a value is a call or invoke to a library function that
85 /// allocates zero-filled memory (such as calloc).
86 bool isCallocLikeFn(const Value *V, const TargetLibraryInfo *TLI,
87  bool LookThroughBitCast = false);
88 
89 /// Tests if a value is a call or invoke to a library function that
90 /// allocates memory similar to malloc or calloc.
91 bool isMallocOrCallocLikeFn(const Value *V, const TargetLibraryInfo *TLI,
92  bool LookThroughBitCast = false);
93 
94 /// Tests if a value is a call or invoke to a library function that
95 /// allocates memory (either malloc, calloc, or strdup like).
96 bool isAllocLikeFn(const Value *V, const TargetLibraryInfo *TLI,
97  bool LookThroughBitCast = false);
98 
99 /// Tests if a value is a call or invoke to a library function that
100 /// reallocates memory (e.g., realloc).
101 bool isReallocLikeFn(const Value *V, const TargetLibraryInfo *TLI,
102  bool LookThroughBitCast = false);
103 
104 /// Tests if a function is a call or invoke to a library function that
105 /// reallocates memory (e.g., realloc).
106 bool isReallocLikeFn(const Function *F, const TargetLibraryInfo *TLI);
107 
108 /// Tests if a value is a call or invoke to a library function that
109 /// allocates memory and throws if an allocation failed (e.g., new).
110 bool isOpNewLikeFn(const Value *V, const TargetLibraryInfo *TLI,
111  bool LookThroughBitCast = false);
112 
113 /// Tests if a value is a call or invoke to a library function that
114 /// allocates memory (strdup, strndup).
115 bool isStrdupLikeFn(const Value *V, const TargetLibraryInfo *TLI,
116  bool LookThroughBitCast = false);
117 
118 //===----------------------------------------------------------------------===//
119 // malloc Call Utility Functions.
120 //
121 
122 /// extractMallocCall - Returns the corresponding CallInst if the instruction
123 /// is a malloc call. Since CallInst::CreateMalloc() only creates calls, we
124 /// ignore InvokeInst here.
125 const CallInst *
126 extractMallocCall(const Value *I,
127  function_ref<const TargetLibraryInfo &(Function &)> GetTLI);
128 inline CallInst *
130  function_ref<const TargetLibraryInfo &(Function &)> GetTLI) {
131  return const_cast<CallInst *>(extractMallocCall((const Value *)I, GetTLI));
132 }
133 
134 /// getMallocType - Returns the PointerType resulting from the malloc call.
135 /// The PointerType depends on the number of bitcast uses of the malloc call:
136 /// 0: PointerType is the malloc calls' return type.
137 /// 1: PointerType is the bitcast's result type.
138 /// >1: Unique PointerType cannot be determined, return NULL.
139 PointerType *getMallocType(const CallInst *CI, const TargetLibraryInfo *TLI);
140 
141 /// getMallocAllocatedType - Returns the Type allocated by malloc call.
142 /// The Type depends on the number of bitcast uses of the malloc call:
143 /// 0: PointerType is the malloc calls' return type.
144 /// 1: PointerType is the bitcast's result type.
145 /// >1: Unique PointerType cannot be determined, return NULL.
146 Type *getMallocAllocatedType(const CallInst *CI, const TargetLibraryInfo *TLI);
147 
148 /// getMallocArraySize - Returns the array size of a malloc call. If the
149 /// argument passed to malloc is a multiple of the size of the malloced type,
150 /// then return that multiple. For non-array mallocs, the multiple is
151 /// constant 1. Otherwise, return NULL for mallocs whose array size cannot be
152 /// determined.
153 Value *getMallocArraySize(CallInst *CI, const DataLayout &DL,
154  const TargetLibraryInfo *TLI,
155  bool LookThroughSExt = false);
156 
157 //===----------------------------------------------------------------------===//
158 // calloc Call Utility Functions.
159 //
160 
161 /// extractCallocCall - Returns the corresponding CallInst if the instruction
162 /// is a calloc call.
163 const CallInst *extractCallocCall(const Value *I, const TargetLibraryInfo *TLI);
165  return const_cast<CallInst*>(extractCallocCall((const Value*)I, TLI));
166 }
167 
168 
169 //===----------------------------------------------------------------------===//
170 // free Call Utility Functions.
171 //
172 
173 /// isLibFreeFunction - Returns true if the function is a builtin free()
174 bool isLibFreeFunction(const Function *F, const LibFunc TLIFn);
175 
176 /// isFreeCall - Returns non-null if the value is a call to the builtin free()
177 const CallInst *isFreeCall(const Value *I, const TargetLibraryInfo *TLI);
178 
179 inline CallInst *isFreeCall(Value *I, const TargetLibraryInfo *TLI) {
180  return const_cast<CallInst*>(isFreeCall((const Value*)I, TLI));
181 }
182 
183 //===----------------------------------------------------------------------===//
184 // Utility functions to compute size of objects.
185 //
186 
187 /// Various options to control the behavior of getObjectSize.
189  /// Controls how we handle conditional statements with unknown conditions.
190  enum class Mode : uint8_t {
191  /// Fail to evaluate an unknown condition.
192  Exact,
193  /// Evaluate all branches of an unknown condition. If all evaluations
194  /// succeed, pick the minimum size.
195  Min,
196  /// Same as Min, except we pick the maximum size of all of the branches.
197  Max
198  };
199 
200  /// How we want to evaluate this object's size.
202  /// Whether to round the result up to the alignment of allocas, byval
203  /// arguments, and global variables.
204  bool RoundToAlign = false;
205  /// If this is true, null pointers in address space 0 will be treated as
206  /// though they can't be evaluated. Otherwise, null is always considered to
207  /// point to a 0 byte region of memory.
208  bool NullIsUnknownSize = false;
209 };
210 
211 /// Compute the size of the object pointed by Ptr. Returns true and the
212 /// object size in Size if successful, and false otherwise. In this context, by
213 /// object we mean the region of memory starting at Ptr to the end of the
214 /// underlying object pointed to by Ptr.
215 ///
216 /// WARNING: The object size returned is the allocation size. This does not
217 /// imply dereferenceability at site of use since the object may be freeed in
218 /// between.
219 bool getObjectSize(const Value *Ptr, uint64_t &Size, const DataLayout &DL,
220  const TargetLibraryInfo *TLI, ObjectSizeOpts Opts = {});
221 
222 /// Try to turn a call to \@llvm.objectsize into an integer value of the given
223 /// Type. Returns null on failure. If MustSucceed is true, this function will
224 /// not return null, and may return conservative values governed by the second
225 /// argument of the call to objectsize.
226 Value *lowerObjectSizeCall(IntrinsicInst *ObjectSize, const DataLayout &DL,
227  const TargetLibraryInfo *TLI, bool MustSucceed);
228 
229 
230 
231 using SizeOffsetType = std::pair<APInt, APInt>;
232 
233 /// Evaluate the size and offset of an object pointed to by a Value*
234 /// statically. Fails if size or offset are not known at compile time.
236  : public InstVisitor<ObjectSizeOffsetVisitor, SizeOffsetType> {
237  const DataLayout &DL;
238  const TargetLibraryInfo *TLI;
239  ObjectSizeOpts Options;
240  unsigned IntTyBits;
241  APInt Zero;
243 
244  APInt align(APInt Size, uint64_t Align);
245 
246  SizeOffsetType unknown() {
247  return std::make_pair(APInt(), APInt());
248  }
249 
250 public:
253 
255 
256  static bool knownSize(const SizeOffsetType &SizeOffset) {
257  return SizeOffset.first.getBitWidth() > 1;
258  }
259 
260  static bool knownOffset(const SizeOffsetType &SizeOffset) {
261  return SizeOffset.second.getBitWidth() > 1;
262  }
263 
264  static bool bothKnown(const SizeOffsetType &SizeOffset) {
265  return knownSize(SizeOffset) && knownOffset(SizeOffset);
266  }
267 
268  // These are "private", except they can't actually be made private. Only
269  // compute() should be used by external users.
285 
286 private:
287  bool CheckedZextOrTrunc(APInt &I);
288 };
289 
290 using SizeOffsetEvalType = std::pair<Value *, Value *>;
291 
292 /// Evaluate the size and offset of an object pointed to by a Value*.
293 /// May create code to compute the result at run-time.
295  : public InstVisitor<ObjectSizeOffsetEvaluator, SizeOffsetEvalType> {
297  using WeakEvalType = std::pair<WeakTrackingVH, WeakTrackingVH>;
300 
301  const DataLayout &DL;
302  const TargetLibraryInfo *TLI;
303  LLVMContext &Context;
304  BuilderTy Builder;
305  IntegerType *IntTy;
306  Value *Zero;
307  CacheMapTy CacheMap;
308  PtrSetTy SeenVals;
309  ObjectSizeOpts EvalOpts;
310  SmallPtrSet<Instruction *, 8> InsertedInstructions;
311 
312  SizeOffsetEvalType compute_(Value *V);
313 
314 public:
316  return std::make_pair(nullptr, nullptr);
317  }
318 
320  LLVMContext &Context, ObjectSizeOpts EvalOpts = {});
321 
323 
324  bool knownSize(SizeOffsetEvalType SizeOffset) {
325  return SizeOffset.first;
326  }
327 
328  bool knownOffset(SizeOffsetEvalType SizeOffset) {
329  return SizeOffset.second;
330  }
331 
332  bool anyKnown(SizeOffsetEvalType SizeOffset) {
333  return knownSize(SizeOffset) || knownOffset(SizeOffset);
334  }
335 
336  bool bothKnown(SizeOffsetEvalType SizeOffset) {
337  return knownSize(SizeOffset) && knownOffset(SizeOffset);
338  }
339 
340  // The individual instruction visitors should be treated as private.
351 };
352 
353 } // end namespace llvm
354 
355 #endif // LLVM_ANALYSIS_MEMORYBUILTINS_H
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::ObjectSizeOffsetEvaluator::unknown
static SizeOffsetEvalType unknown()
Definition: MemoryBuiltins.h:315
llvm::SizeOffsetType
std::pair< APInt, APInt > SizeOffsetType
Definition: MemoryBuiltins.h:231
llvm::Argument
This class represents an incoming formal argument to a Function.
Definition: Argument.h:29
PointerType
Definition: ItaniumDemangle.h:477
llvm::isMallocOrCallocLikeFn
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...
Definition: MemoryBuiltins.cpp:298
llvm::ObjectSizeOffsetVisitor::visitGlobalAlias
SizeOffsetType visitGlobalAlias(GlobalAlias &GA)
Definition: MemoryBuiltins.cpp:793
llvm
Definition: AllocatorList.h:23
llvm::isCallocLikeFn
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...
Definition: MemoryBuiltins.cpp:291
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:112
llvm::ExtractElementInst
This instruction extracts a single (scalar) element from a VectorType value.
Definition: Instructions.h:1878
llvm::Function
Definition: Function.h:61
TargetFolder.h
llvm::ObjectSizeOffsetEvaluator::compute
SizeOffsetEvalType compute(Value *V)
Definition: MemoryBuiltins.cpp:872
llvm::ObjectSizeOffsetVisitor::visitExtractValueInst
SizeOffsetType visitExtractValueInst(ExtractValueInst &I)
Definition: MemoryBuiltins.cpp:779
llvm::IRBuilder< TargetFolder, IRBuilderCallbackInserter >
llvm::GlobalVariable
Definition: GlobalVariable.h:40
llvm::ObjectSizeOffsetEvaluator::visitSelectInst
SizeOffsetEvalType visitSelectInst(SelectInst &I)
Definition: MemoryBuiltins.cpp:1075
llvm::ObjectSizeOffsetEvaluator::visitGEPOperator
SizeOffsetEvalType visitGEPOperator(GEPOperator &GEP)
Definition: MemoryBuiltins.cpp:1014
llvm::GlobalAlias
Definition: GlobalAlias.h:27
llvm::isAllocLikeFn
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,...
Definition: MemoryBuiltins.cpp:306
APInt.h
DenseMap.h
llvm::ObjectSizeOpts::NullIsUnknownSize
bool NullIsUnknownSize
If this is true, null pointers in address space 0 will be treated as though they can't be evaluated.
Definition: MemoryBuiltins.h:208
llvm::ObjectSizeOffsetEvaluator::visitCallBase
SizeOffsetEvalType visitCallBase(CallBase &CB)
Definition: MemoryBuiltins.cpp:973
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:449
llvm::ObjectSizeOpts::RoundToAlign
bool RoundToAlign
Whether to round the result up to the alignment of allocas, byval arguments, and global variables.
Definition: MemoryBuiltins.h:204
llvm::ObjectSizeOffsetEvaluator::visitLoadInst
SizeOffsetEvalType visitLoadInst(LoadInst &I)
Definition: MemoryBuiltins.cpp:1029
llvm::isAllocationFn
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...
Definition: MemoryBuiltins.cpp:242
F
#define F(x, y, z)
Definition: MD5.cpp:56
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::ObjectSizeOffsetEvaluator::visitIntToPtrInst
SizeOffsetEvalType visitIntToPtrInst(IntToPtrInst &)
Definition: MemoryBuiltins.cpp:1024
llvm::ConstantPointerNull
A constant pointer value that points to null.
Definition: Constants.h:533
llvm::getMallocArraySize
Value * getMallocArraySize(CallInst *CI, const DataLayout &DL, const TargetLibraryInfo *TLI, bool LookThroughSExt=false)
getMallocArraySize - Returns the array size of a malloc call.
Definition: MemoryBuiltins.cpp:419
llvm::getMallocAllocatedType
Type * getMallocAllocatedType(const CallInst *CI, const TargetLibraryInfo *TLI)
getMallocAllocatedType - Returns the Type allocated by malloc call.
Definition: MemoryBuiltins.cpp:408
llvm::ObjectSizeOffsetVisitor::bothKnown
static bool bothKnown(const SizeOffsetType &SizeOffset)
Definition: MemoryBuiltins.h:264
llvm::ObjectSizeOffsetEvaluator::knownSize
bool knownSize(SizeOffsetEvalType SizeOffset)
Definition: MemoryBuiltins.h:324
llvm::LibFunc
LibFunc
Definition: TargetLibraryInfo.h:34
llvm::ObjectSizeOffsetVisitor::visitIntToPtrInst
SizeOffsetType visitIntToPtrInst(IntToPtrInst &)
Definition: MemoryBuiltins.cpp:807
llvm::ObjectSizeOffsetEvaluator::ObjectSizeOffsetEvaluator
ObjectSizeOffsetEvaluator(const DataLayout &DL, const TargetLibraryInfo *TLI, LLVMContext &Context, ObjectSizeOpts EvalOpts={})
Definition: MemoryBuiltins.cpp:860
llvm::ObjectSizeOpts::Mode::Exact
@ Exact
Fail to evaluate an unknown condition.
llvm::getMallocType
PointerType * getMallocType(const CallInst *CI, const TargetLibraryInfo *TLI)
getMallocType - Returns the PointerType resulting from the malloc call.
Definition: MemoryBuiltins.cpp:377
TargetLibraryInfo.h
llvm::IntegerType
Class to represent integer types.
Definition: DerivedTypes.h:40
llvm::ObjectSizeOffsetVisitor::visitGlobalVariable
SizeOffsetType visitGlobalVariable(GlobalVariable &GV)
Definition: MemoryBuiltins.cpp:799
llvm::Instruction
Definition: Instruction.h:45
llvm::ObjectSizeOffsetVisitor::visitAllocaInst
SizeOffsetType visitAllocaInst(AllocaInst &I)
Definition: MemoryBuiltins.cpp:664
llvm::ObjectSizeOffsetEvaluator::visitExtractElementInst
SizeOffsetEvalType visitExtractElementInst(ExtractElementInst &I)
Definition: MemoryBuiltins.cpp:1004
Options
const char LLVMTargetMachineRef LLVMPassBuilderOptionsRef Options
Definition: PassBuilderBindings.cpp:48
llvm::ObjectSizeOffsetEvaluator
Evaluate the size and offset of an object pointed to by a Value*.
Definition: MemoryBuiltins.h:294
llvm::isReallocLikeFn
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....
Definition: MemoryBuiltins.cpp:313
SmallPtrSet.h
llvm::ObjectSizeOffsetEvaluator::visitPHINode
SizeOffsetEvalType visitPHINode(PHINode &PHI)
Definition: MemoryBuiltins.cpp:1033
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::getObjectSize
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.
Definition: MemoryBuiltins.cpp:515
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:168
llvm::isMallocLikeFn
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 ...
Definition: MemoryBuiltins.cpp:264
llvm::extractCallocCall
const CallInst * extractCallocCall(const Value *I, const TargetLibraryInfo *TLI)
extractCallocCall - Returns the corresponding CallInst if the instruction is a calloc call.
Definition: MemoryBuiltins.cpp:428
llvm::isStrdupLikeFn
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,...
Definition: MemoryBuiltins.cpp:333
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
llvm::DenseMap< const Value *, WeakEvalType >
llvm::ObjectSizeOffsetVisitor::visitUndefValue
SizeOffsetType visitUndefValue(UndefValue &)
Definition: MemoryBuiltins.cpp:850
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::UndefValue
'undef' values are things that do not have specified contents.
Definition: Constants.h:1347
llvm::ObjectSizeOffsetVisitor
Evaluate the size and offset of an object pointed to by a Value* statically.
Definition: MemoryBuiltins.h:235
llvm::lowerObjectSizeCall
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.
Definition: MemoryBuiltins.cpp:526
llvm::ObjectSizeOffsetVisitor::visitSelectInst
SizeOffsetType visitSelectInst(SelectInst &I)
Definition: MemoryBuiltins.cpp:822
TemplateParamKind::Type
@ Type
IRBuilder.h
llvm::extractMallocCall
const CallInst * extractMallocCall(const Value *I, function_ref< const TargetLibraryInfo &(Function &)> GetTLI)
extractMallocCall - Returns the corresponding CallInst if the instruction is a malloc call.
Definition: MemoryBuiltins.cpp:341
llvm::ObjectSizeOpts::Mode::Min
@ Min
Evaluate all branches of an unknown condition.
llvm::isAlignedAllocLikeFn
bool isAlignedAllocLikeFn(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 with a...
Definition: MemoryBuiltins.cpp:277
llvm::SelectInst
This class represents the LLVM 'select' instruction.
Definition: Instructions.h:1743
llvm::GEPOperator
Definition: Operator.h:457
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:70
llvm::ObjectSizeOffsetEvaluator::visitAllocaInst
SizeOffsetEvalType visitAllocaInst(AllocaInst &I)
Definition: MemoryBuiltins.cpp:953
InstVisitor.h
llvm::ObjectSizeOffsetVisitor::visitGEPOperator
SizeOffsetType visitGEPOperator(GEPOperator &GEP)
Definition: MemoryBuiltins.cpp:784
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::InstVisitor
Base class for instruction visitors.
Definition: InstVisitor.h:79
llvm::ObjectSizeOpts
Various options to control the behavior of getObjectSize.
Definition: MemoryBuiltins.h:188
llvm::LoadInst
An instruction for reading from memory.
Definition: Instructions.h:174
llvm::isOpNewLikeFn
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...
Definition: MemoryBuiltins.cpp:326
ValueHandle.h
llvm::ObjectSizeOpts::Mode::Max
@ Max
Same as Min, except we pick the maximum size of all of the branches.
llvm::ObjectSizeOffsetVisitor::visitLoadInst
SizeOffsetType visitLoadInst(LoadInst &I)
Definition: MemoryBuiltins.cpp:812
llvm::ObjectSizeOffsetEvaluator::knownOffset
bool knownOffset(SizeOffsetEvalType SizeOffset)
Definition: MemoryBuiltins.h:328
llvm::ObjectSizeOffsetVisitor::visitInstruction
SizeOffsetType visitInstruction(Instruction &I)
Definition: MemoryBuiltins.cpp:854
llvm::ObjectSizeOffsetVisitor::visitCallBase
SizeOffsetType visitCallBase(CallBase &CB)
Definition: MemoryBuiltins.cpp:701
llvm::ObjectSizeOffsetVisitor::visitArgument
SizeOffsetType visitArgument(Argument &A)
Definition: MemoryBuiltins.cpp:689
llvm::ObjectSizeOpts::Mode
Mode
Controls how we handle conditional statements with unknown conditions.
Definition: MemoryBuiltins.h:190
llvm::isNoAliasFn
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...
Definition: MemoryBuiltins.cpp:254
llvm::ObjectSizeOpts::EvalMode
Mode EvalMode
How we want to evaluate this object's size.
Definition: MemoryBuiltins.h:201
llvm::ExtractValueInst
This instruction extracts a struct member or array element value from an aggregate value.
Definition: Instructions.h:2346
llvm::SizeOffsetEvalType
std::pair< Value *, Value * > SizeOffsetEvalType
Definition: MemoryBuiltins.h:290
llvm::ObjectSizeOffsetVisitor::knownOffset
static bool knownOffset(const SizeOffsetType &SizeOffset)
Definition: MemoryBuiltins.h:260
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:219
llvm::IntToPtrInst
This class represents a cast from an integer to a pointer.
Definition: Instructions.h:5072
llvm::ObjectSizeOffsetVisitor::compute
SizeOffsetType compute(Value *V)
Definition: MemoryBuiltins.cpp:611
llvm::ObjectSizeOffsetVisitor::visitConstantPointerNull
SizeOffsetType visitConstantPointerNull(ConstantPointerNull &)
Definition: MemoryBuiltins.cpp:760
llvm::ObjectSizeOffsetEvaluator::visitExtractValueInst
SizeOffsetEvalType visitExtractValueInst(ExtractValueInst &I)
Definition: MemoryBuiltins.cpp:1009
llvm::ObjectSizeOffsetEvaluator::visitInstruction
SizeOffsetEvalType visitInstruction(Instruction &I)
Definition: MemoryBuiltins.cpp:1091
llvm::ObjectSizeOffsetVisitor::knownSize
static bool knownSize(const SizeOffsetType &SizeOffset)
Definition: MemoryBuiltins.h:256
llvm::PHINode
Definition: Instructions.h:2600
llvm::ObjectSizeOffsetEvaluator::bothKnown
bool bothKnown(SizeOffsetEvalType SizeOffset)
Definition: MemoryBuiltins.h:336
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1164
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1478
llvm::ObjectSizeOffsetVisitor::ObjectSizeOffsetVisitor
ObjectSizeOffsetVisitor(const DataLayout &DL, const TargetLibraryInfo *TLI, LLVMContext &Context, ObjectSizeOpts Options={})
Definition: MemoryBuiltins.cpp:602
GEP
Hexagon Common GEP
Definition: HexagonCommonGEP.cpp:171
llvm::AllocaInst
an instruction to allocate memory on the stack
Definition: Instructions.h:61
llvm::isLibFreeFunction
bool isLibFreeFunction(const Function *F, const LibFunc TLIFn)
isLibFreeFunction - Returns true if the function is a builtin free()
Definition: MemoryBuiltins.cpp:434
llvm::ObjectSizeOffsetVisitor::visitExtractElementInst
SizeOffsetType visitExtractElementInst(ExtractElementInst &I)
Definition: MemoryBuiltins.cpp:774
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::ObjectSizeOffsetEvaluator::anyKnown
bool anyKnown(SizeOffsetEvalType SizeOffset)
Definition: MemoryBuiltins.h:332
llvm::isFreeCall
const CallInst * isFreeCall(const Value *I, const TargetLibraryInfo *TLI)
isFreeCall - Returns non-null if the value is a call to the builtin free()
Definition: MemoryBuiltins.cpp:486
llvm::ObjectSizeOffsetVisitor::visitPHINode
SizeOffsetType visitPHINode(PHINode &)
Definition: MemoryBuiltins.cpp:817