LLVM
8.0.1
|
#include "llvm/Transforms/Instrumentation/BoundsChecking.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/TargetFolder.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/Value.h"
#include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdint>
#include <vector>
Go to the source code of this file.
Macros | |
#define | DEBUG_TYPE "bounds-checking" |
Typedefs | |
using | BuilderTy = IRBuilder< TargetFolder > |
Functions | |
STATISTIC (ChecksAdded, "Bounds checks added") | |
STATISTIC (ChecksSkipped, "Bounds checks skipped") | |
STATISTIC (ChecksUnable, "Bounds checks unable to add") | |
static Value * | getBoundsCheckCond (Value *Ptr, Value *InstVal, const DataLayout &DL, TargetLibraryInfo &TLI, ObjectSizeOffsetEvaluator &ObjSizeEval, BuilderTy &IRB, ScalarEvolution &SE) |
Gets the conditions under which memory accessing instructions will overflow. More... | |
template<typename GetTrapBBT > | |
static void | insertBoundsCheck (Value *Or, BuilderTy IRB, GetTrapBBT GetTrapBB) |
Adds run-time bounds checks to memory accessing instructions. More... | |
static bool | addBoundsChecking (Function &F, TargetLibraryInfo &TLI, ScalarEvolution &SE) |
INITIALIZE_PASS_BEGIN (BoundsCheckingLegacyPass, "bounds-checking", "Run-time bounds checking", false, false) INITIALIZE_PASS_END(BoundsCheckingLegacyPass | |
Variables | |
static cl::opt< bool > | SingleTrapBB ("bounds-checking-single-trap", cl::desc("Use one trap block per function")) |
bounds | checking |
bounds Run time bounds | false |
#define DEBUG_TYPE "bounds-checking" |
Definition at line 39 of file BoundsChecking.cpp.
using BuilderTy = IRBuilder<TargetFolder> |
Definition at line 48 of file BoundsChecking.cpp.
|
static |
Definition at line 143 of file BoundsChecking.cpp.
References llvm::BasicBlock::Create(), getBoundsCheckCond(), llvm::Function::getContext(), llvm::Module::getDataLayout(), llvm::Intrinsic::getDeclaration(), llvm::Instruction::getParent(), llvm::GlobalValue::getParent(), I, insertBoundsCheck(), llvm::instructions(), llvm::CallBase::setDoesNotReturn(), SI, SingleTrapBB, and llvm::Intrinsic::trap.
Referenced by llvm::BoundsCheckingPass::run().
|
static |
Gets the conditions under which memory accessing instructions will overflow.
Ptr
is the pointer that will be read/written, and InstVal
is either the result from the load or the value being stored. It is used to determine the size of memory block that is touched.
Returns the condition under which the access will overflow.
Definition at line 57 of file BoundsChecking.cpp.
References llvm::ObjectSizeOffsetEvaluator::bothKnown(), llvm::ObjectSizeOffsetEvaluator::compute(), llvm::IRBuilder< T, Inserter >::CreateICmpSLT(), llvm::IRBuilder< T, Inserter >::CreateICmpULT(), llvm::IRBuilder< T, Inserter >::CreateOr(), llvm::IRBuilder< T, Inserter >::CreateSub(), llvm::dbgs(), llvm::dyn_cast(), llvm::ConstantInt::get(), llvm::Value::getContext(), llvm::ConstantInt::getFalse(), llvm::DataLayout::getIntPtrType(), llvm::ScalarEvolution::getSCEV(), llvm::Value::getType(), llvm::DataLayout::getTypeStoreSize(), llvm::ScalarEvolution::getUnsignedRange(), llvm::ConstantInt::getValue(), LLVM_DEBUG, Size, and llvm::APInt::slt().
Referenced by addBoundsChecking().
INITIALIZE_PASS_BEGIN | ( | BoundsCheckingLegacyPass | , |
"bounds-checking" | , | ||
"Run-time bounds checking" | , | ||
false | , | ||
false | |||
) |
Referenced by llvm::BoundsCheckingPass::run().
|
static |
Adds run-time bounds checks to memory accessing instructions.
Or
is the condition that should guard the trap.
GetTrapBB
is a callable that returns the trap BB to use on failure.
Definition at line 115 of file BoundsChecking.cpp.
References C, llvm::BranchInst::Create(), llvm::Instruction::eraseFromParent(), llvm::IRBuilderBase::GetInsertPoint(), llvm::BasicBlock::getTerminator(), llvm::ConstantInt::getZExtValue(), and llvm::BasicBlock::splitBasicBlock().
Referenced by addBoundsChecking().
STATISTIC | ( | ChecksAdded | , |
"Bounds checks added" | |||
) |
STATISTIC | ( | ChecksSkipped | , |
"Bounds checks skipped" | |||
) |
STATISTIC | ( | ChecksUnable | , |
"Bounds checks unable to add" | |||
) |
bounds Run time bounds checking |
Definition at line 243 of file BoundsChecking.cpp.
bounds Run time bounds false |
Definition at line 243 of file BoundsChecking.cpp.
|
static |
Referenced by addBoundsChecking().