LLVM 20.0.0git
|
#include "llvm/Transforms/Instrumentation/BoundsChecking.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringRef.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/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include <utility>
Go to the source code of this file.
Classes | |
struct | ReportingOpts |
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. | |
static CallInst * | InsertTrap (BuilderTy &IRB) |
static CallInst * | InsertCall (BuilderTy &IRB, bool MayReturn, StringRef Name) |
template<typename GetTrapBBT > | |
static void | insertBoundsCheck (Value *Or, BuilderTy &IRB, GetTrapBBT GetTrapBB) |
Adds run-time bounds checks to memory accessing instructions. | |
static bool | addBoundsChecking (Function &F, TargetLibraryInfo &TLI, ScalarEvolution &SE, const ReportingOpts &Opts) |
Variables | |
static cl::opt< bool > | SingleTrapBB ("bounds-checking-single-trap", cl::desc("Use one trap block per function")) |
static cl::opt< bool > | DebugTrapBB ("bounds-checking-unique-traps", cl::desc("Always use one trap per check")) |
#define DEBUG_TYPE "bounds-checking" |
Definition at line 35 of file BoundsChecking.cpp.
using BuilderTy = IRBuilder<TargetFolder> |
Definition at line 47 of file BoundsChecking.cpp.
|
static |
Definition at line 199 of file BoundsChecking.cpp.
References llvm::CallBase::addFnAttr(), llvm::BasicBlock::Create(), DebugTrapBB, DL, llvm::SmallVectorBase< Size_T >::empty(), llvm::ObjectSizeOpts::EvalMode, F, getBoundsCheckCond(), llvm::Function::getContext(), llvm::GlobalValue::getParent(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), I, insertBoundsCheck(), InsertCall(), InsertTrap(), instructions, ReportingOpts::MayReturn, ReportingOpts::Name, llvm::Or, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::ObjectSizeOpts::RoundToAlign, llvm::Instruction::setDebugLoc(), llvm::CallBase::setDoesNotReturn(), llvm::CallBase::setDoesNotThrow(), SingleTrapBB, and ReportingOpts::UseTrap.
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 56 of file BoundsChecking.cpp.
References llvm::SizeOffsetType< T, C >::bothKnown(), llvm::ObjectSizeOffsetEvaluator::compute(), llvm::IRBuilderBase::CreateICmpSLT(), llvm::IRBuilderBase::CreateICmpULT(), llvm::IRBuilderBase::CreateOr(), llvm::IRBuilderBase::CreateSub(), llvm::IRBuilderBase::CreateTypeSize(), llvm::dbgs(), DL, llvm::ConstantInt::getFalse(), llvm::ScalarEvolution::getSCEV(), llvm::Value::getType(), llvm::ScalarEvolution::getUnsignedRange(), llvm::ConstantInt::getValue(), LLVM_DEBUG, llvm::SizeOffsetType< T, C >::Offset, llvm::Offset, llvm::Or, Ptr, llvm::SizeOffsetType< T, C >::Size, Size, and llvm::APInt::slt().
Referenced by addBoundsChecking().
|
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 138 of file BoundsChecking.cpp.
References llvm::CallingConv::C, llvm::BranchInst::Create(), llvm::Instruction::eraseFromParent(), llvm::IRBuilderBase::GetInsertPoint(), llvm::BasicBlock::getParent(), llvm::BasicBlock::getTerminator(), llvm::Or, and llvm::BasicBlock::splitBasicBlock().
Referenced by addBoundsChecking().
Definition at line 118 of file BoundsChecking.cpp.
References B, llvm::IRBuilderBase::CreateCall(), llvm::AttributeList::FunctionIndex, llvm::AttributeList::get(), llvm::Function::getContext(), llvm::IRBuilderBase::GetInsertBlock(), llvm::Module::getOrInsertFunction(), llvm::GlobalValue::getParent(), llvm::BasicBlock::getParent(), llvm::Type::getVoidTy(), and Name.
Referenced by addBoundsChecking().
Definition at line 108 of file BoundsChecking.cpp.
References llvm::IRBuilderBase::CreateIntrinsic(), DebugTrapBB, llvm::IRBuilderBase::GetInsertBlock(), llvm::IRBuilderBase::getInt8Ty(), llvm::BasicBlock::getParent(), and llvm::Function::size().
Referenced by addBoundsChecking().
STATISTIC | ( | ChecksAdded | , |
"Bounds checks added" | |||
) |
STATISTIC | ( | ChecksSkipped | , |
"Bounds checks skipped" | |||
) |
STATISTIC | ( | ChecksUnable | , |
"Bounds checks unable to add" | |||
) |
|
static |
Referenced by addBoundsChecking(), and InsertTrap().