本文整理汇总了C++中CallInst::setDoesNotReturn方法的典型用法代码示例。如果您正苦于以下问题:C++ CallInst::setDoesNotReturn方法的具体用法?C++ CallInst::setDoesNotReturn怎么用?C++ CallInst::setDoesNotReturn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CallInst
的用法示例。
在下文中一共展示了CallInst::setDoesNotReturn方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: itostr
Instruction *AddressSanitizer::generateCrashCode(
IRBuilder<> &IRB, Value *Addr, bool IsWrite, uint32_t TypeSize) {
// IsWrite and TypeSize are encoded in the function name.
std::string FunctionName = std::string(kAsanReportErrorTemplate) +
(IsWrite ? "store" : "load") + itostr(TypeSize / 8);
Value *ReportWarningFunc = CurrentModule->getOrInsertFunction(
FunctionName, IRB.getVoidTy(), IntptrTy, NULL);
CallInst *Call = IRB.CreateCall(ReportWarningFunc, Addr);
Call->setDoesNotReturn();
return Call;
}
示例2: doCallPC
static InstTransResult doCallPC(InstPtr ip, BasicBlock *&b, VA tgtAddr) {
Module *M = b->getParent()->getParent();
Function *ourF = b->getParent();
//insert a call to the call function
//this function will be a translated function that we emit, so we should
//be able to look it up in our module.
std::string fname = "sub_"+to_string<VA>(tgtAddr, std::hex);
Function *F = M->getFunction(fname);
TASSERT( F != NULL, "Could not find function: " + fname );
writeFakeReturnAddr(b);
//we need to wrap up our current context
writeLocalsToContext(b, 32, ABICallStore);
//make the call, the only argument should be our parents arguments
TASSERT(ourF->arg_size() == 1, "");
std::vector<Value*> subArgs;
subArgs.push_back(ourF->arg_begin());
CallInst *c = CallInst::Create(F, subArgs, "", b);
c->setCallingConv(F->getCallingConv());
if ( ip->has_local_noreturn() ) {
// noreturn functions just hit unreachable
std::cout << __FUNCTION__ << ": Adding Unreachable Instruction to local noreturn" << std::endl;
c->setDoesNotReturn();
c->setTailCall();
Value *unreachable = new UnreachableInst(b->getContext(), b);
return EndBlock;
}
//spill our context back
writeContextToLocals(b, 32, ABIRetSpill);
//and we can continue to run the old code
return ContinueBlock;
}
示例3:
/// getTrapBB - create a basic block that traps. All overflowing conditions
/// branch to this block. There's only one trap block per function.
BasicBlock *BoundsChecking::getTrapBB() {
if (TrapBB && SingleTrapBB)
return TrapBB;
Function *Fn = Inst->getParent()->getParent();
BasicBlock::iterator PrevInsertPoint = Builder->GetInsertPoint();
TrapBB = BasicBlock::Create(Fn->getContext(), "trap", Fn);
Builder->SetInsertPoint(TrapBB);
llvm::Value *F = Intrinsic::getDeclaration(Fn->getParent(), Intrinsic::trap);
CallInst *TrapCall = Builder->CreateCall(F);
TrapCall->setDoesNotReturn();
TrapCall->setDoesNotThrow();
TrapCall->setDebugLoc(Inst->getDebugLoc());
Builder->CreateUnreachable();
Builder->SetInsertPoint(PrevInsertPoint);
return TrapBB;
}
示例4: addBoundsChecking
static bool addBoundsChecking(Function &F, TargetLibraryInfo &TLI,
ScalarEvolution &SE) {
const DataLayout &DL = F.getParent()->getDataLayout();
ObjectSizeOffsetEvaluator ObjSizeEval(DL, &TLI, F.getContext(),
/*RoundToAlign=*/true);
// check HANDLE_MEMORY_INST in include/llvm/Instruction.def for memory
// touching instructions
SmallVector<std::pair<Instruction *, Value *>, 4> TrapInfo;
for (Instruction &I : instructions(F)) {
Value *Or = nullptr;
BuilderTy IRB(I.getParent(), BasicBlock::iterator(&I), TargetFolder(DL));
if (LoadInst *LI = dyn_cast<LoadInst>(&I)) {
Or = getBoundsCheckCond(LI->getPointerOperand(), LI, DL, TLI,
ObjSizeEval, IRB, SE);
} else if (StoreInst *SI = dyn_cast<StoreInst>(&I)) {
Or = getBoundsCheckCond(SI->getPointerOperand(), SI->getValueOperand(),
DL, TLI, ObjSizeEval, IRB, SE);
} else if (AtomicCmpXchgInst *AI = dyn_cast<AtomicCmpXchgInst>(&I)) {
Or = getBoundsCheckCond(AI->getPointerOperand(), AI->getCompareOperand(),
DL, TLI, ObjSizeEval, IRB, SE);
} else if (AtomicRMWInst *AI = dyn_cast<AtomicRMWInst>(&I)) {
Or = getBoundsCheckCond(AI->getPointerOperand(), AI->getValOperand(), DL,
TLI, ObjSizeEval, IRB, SE);
}
if (Or)
TrapInfo.push_back(std::make_pair(&I, Or));
}
// Create a trapping basic block on demand using a callback. Depending on
// flags, this will either create a single block for the entire function or
// will create a fresh block every time it is called.
BasicBlock *TrapBB = nullptr;
auto GetTrapBB = [&TrapBB](BuilderTy &IRB) {
if (TrapBB && SingleTrapBB)
return TrapBB;
Function *Fn = IRB.GetInsertBlock()->getParent();
// FIXME: This debug location doesn't make a lot of sense in the
// `SingleTrapBB` case.
auto DebugLoc = IRB.getCurrentDebugLocation();
IRBuilder<>::InsertPointGuard Guard(IRB);
TrapBB = BasicBlock::Create(Fn->getContext(), "trap", Fn);
IRB.SetInsertPoint(TrapBB);
auto *F = Intrinsic::getDeclaration(Fn->getParent(), Intrinsic::trap);
CallInst *TrapCall = IRB.CreateCall(F, {});
TrapCall->setDoesNotReturn();
TrapCall->setDoesNotThrow();
TrapCall->setDebugLoc(DebugLoc);
IRB.CreateUnreachable();
return TrapBB;
};
// Add the checks.
for (const auto &Entry : TrapInfo) {
Instruction *Inst = Entry.first;
BuilderTy IRB(Inst->getParent(), BasicBlock::iterator(Inst), TargetFolder(DL));
insertBoundsCheck(Entry.second, IRB, GetTrapBB);
}
return !TrapInfo.empty();
}
示例5: doCallPCExtern
static InstTransResult doCallPCExtern(BasicBlock *&b, std::string target, bool esp_adjust = false) {
Module *M = b->getParent()->getParent();
//write it into the location pointer to by ESP-4
Value *espOld = R_READ<32>(b, X86::ESP);
//Value *espSub =
// BinaryOperator::CreateSub(espOld, CONST_V<32>(b, 4), "", b);
//M_WRITE_0<32>(b, espSub, CONST_V<32>(b, 0));
//R_WRITE<32>(b, X86::ESP, espSub);
//write the local values into the context register
//for now, we will stop doing this because we are not calling a wrapper
//that meaningfully understands the context structure
//writeLocalsToContext(b, 32);
//lookup the function in the module
Function *externFunction = M->getFunction(target);
TASSERT(externFunction != NULL, "Coult not find external function: "+target);
FunctionType *externFunctionTy = externFunction->getFunctionType();
Type *rType = externFunction->getReturnType();
int paramCount = externFunctionTy->getNumParams();
//now we need to do a series of reads off the stack, essentially
//a series of POPs but without writing anything back to ESP
Value *baseEspVal=NULL;
std::vector<Value *> arguments;
// in fastcall, the first two params are passed via register
// only need to adjust stack if there are more than two args
if( externFunction->getCallingConv() == CallingConv::X86_FastCall)
{
Function::ArgumentListType::iterator it =
externFunction->getArgumentList().begin();
Function::ArgumentListType::iterator end =
externFunction->getArgumentList().end();
AttrBuilder B;
B.addAttribute(Attribute::InReg);
if(paramCount && it != end) {
Value *r_ecx = R_READ<32>(b, X86::ECX);
arguments.push_back(r_ecx);
--paramCount;
// set argument 1's attribute: make it in a register
it->addAttr(AttributeSet::get(it->getContext(), 1, B));
++it;
}
if(paramCount && it != end) {
Value *r_edx = R_READ<32>(b, X86::EDX);
arguments.push_back(r_edx);
--paramCount;
// set argument 2's attribute: make it in a register
it->addAttr(AttributeSet::get(it->getContext(), 2, B));
++it;
}
}
if( paramCount ) {
baseEspVal = R_READ<32>(b, X86::ESP);
if(esp_adjust) {
baseEspVal =
BinaryOperator::CreateAdd(baseEspVal, CONST_V<32>(b, 4), "", b);
}
}
for( int i = 0; i < paramCount; i++ ) {
Value *vFromStack = M_READ_0<32>(b, baseEspVal);
arguments.push_back(vFromStack);
if( i+1 != paramCount ) {
baseEspVal =
BinaryOperator::CreateAdd(baseEspVal, CONST_V<32>(b, 4), "", b);
}
}
CallInst *callR = CallInst::Create(externFunction, arguments, "", b);
callR->setCallingConv(externFunction->getCallingConv());
noAliasMCSemaScope(callR);
if ( externFunction->doesNotReturn() ) {
// noreturn functions just hit unreachable
std::cout << __FUNCTION__ << ": Adding Unreachable Instruction" << std::endl;
callR->setDoesNotReturn();
callR->setTailCall();
Value *unreachable = new UnreachableInst(b->getContext(), b);
return EndBlock;
}
//then, put the registers back into the locals
//see above
//writeContextToLocals(b, 32);
//.........这里部分代码省略.........