本文整理汇总了C++中InvokeInst::getArgOperand方法的典型用法代码示例。如果您正苦于以下问题:C++ InvokeInst::getArgOperand方法的具体用法?C++ InvokeInst::getArgOperand怎么用?C++ InvokeInst::getArgOperand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InvokeInst
的用法示例。
在下文中一共展示了InvokeInst::getArgOperand方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runOnModule
bool FuncAddrTaken::runOnModule(Module &M) {
bool Changed = false;
// add declaration of function __patch_at
// declare void @__patch_at(void)
FunctionType *FT = FunctionType::get(Type::getVoidTy(M.getContext()),
false);
Function* PatchAt = Function::Create(FT, Function::ExternalLinkage, "__patch_at", &M);
if (PatchAt->getName() != "__patch_at") {
PatchAt->eraseFromParent();
return false;
}
Changed = true;
// Simple optimization so that no function address will be taken twice
// in the same basic block.
std::map<BasicBlock*, std::set<std::string> > UniqPatchAt;
// before each store instruction that manipulates a function, create a call
// to __patch_at
for (auto F = M.getFunctionList().begin(); F != M.getFunctionList().end(); F++) {
for (auto BB = F->begin(); BB != F->end(); BB++) {
for (auto MI = BB->begin(); MI != BB->end(); MI++) {
if (isa<StoreInst>(MI)) {
// check if the store inst moves a function to a variable
Value *V = InnerMost(cast<StoreInst>(MI)->getValueOperand());
addPatchAt(M, FT, V, MI, UniqPatchAt);
if (isa<ConstantVector>(V)) {
std::set<Value*> patched;
for (unsigned i = 0; i < cast<ConstantVector>(V)->getNumOperands(); i++) {
Value *VV = InnerMost(cast<ConstantVector>(V)->getOperand(i));
if (patched.find(VV) == patched.end()) {
addPatchAt(M, FT, VV, MI, UniqPatchAt);
patched.insert(VV);
}
}
} else if (isa<ConstantStruct>(V)) {
std::set<Value*> patched;
for (unsigned i = 0; i < cast<ConstantStruct>(V)->getNumOperands(); i++) {
Value *VV = InnerMost(cast<ConstantStruct>(V)->getOperand(i));
if (patched.find(VV) == patched.end()) {
addPatchAt(M, FT, VV, MI, UniqPatchAt);
patched.insert(VV);
}
}
} else if (isa<ConstantArray>(V)) {
std::set<Value*> patched;
for (unsigned i = 0; i < cast<ConstantArray>(V)->getNumOperands(); i++) {
Value *VV = InnerMost(cast<ConstantArray>(V)->getOperand(i));
if (patched.find(VV) == patched.end()) {
addPatchAt(M, FT, VV, MI, UniqPatchAt);
patched.insert(VV);
}
}
}
} else if (isa<SelectInst>(MI)) {
Value *V = InnerMost(cast<SelectInst>(MI)->getTrueValue());
addPatchAt(M, FT, V, MI, UniqPatchAt);
V = InnerMost(cast<SelectInst>(MI)->getFalseValue());
addPatchAt(M, FT, V, MI, UniqPatchAt);
} else if (isa<CallInst>(MI)) {
CallInst* CI = cast<CallInst>(MI);
for (unsigned i = 0; i < CI->getNumArgOperands(); i++) {
Value *V = InnerMost(CI->getArgOperand(i));
addPatchAt(M, FT, V, MI, UniqPatchAt);
}
} else if (isa<InvokeInst>(MI)) {
InvokeInst* CI = cast<InvokeInst>(MI);
for (unsigned i = 0; i < CI->getNumArgOperands(); i++) {
Value *V = InnerMost(CI->getArgOperand(i));
addPatchAt(M, FT, V, MI, UniqPatchAt);
}
} else if (isa<ReturnInst>(MI)) {
Value *V = cast<ReturnInst>(MI)->getReturnValue();
if (V) {
V = InnerMost(V);
addPatchAt(M, FT, V, MI, UniqPatchAt);
}
} else if (isa<PHINode>(MI)) {
for (unsigned i = 0; i < cast<PHINode>(MI)->getNumIncomingValues(); i++) {
Value *V = InnerMost(cast<PHINode>(MI)->getIncomingValue(i));
BasicBlock* BB = cast<PHINode>(MI)->getIncomingBlock(i);
// right before the last (maybe terminator) instruction.
addPatchAt(M, FT, V, &(BB->back()), UniqPatchAt);
}
}
}
}
}
// TODO: separate the following virtual table traversal code into another pass
for (auto G = M.getGlobalList().begin(); G != M.getGlobalList().end(); G++) {
if (isa<GlobalVariable>(G) &&
cast<GlobalVariable>(G)->hasInitializer()) {
const GlobalVariable *GV = cast<GlobalVariable>(G);
const Constant *C = GV->getInitializer();
if (GV->hasName() && isa<ConstantArray>(C) && GV->getName().startswith("_ZTV")) {
std::string VTName = CXXDemangledName(GV->getName().data());
if (VTName.size() && VTName.find("vtable") == 0) {
//llvm::errs() << VTName << "\n";
VTName = VTName.substr(11); // get pass "vtable for "
//.........这里部分代码省略.........
示例2: handle_inst
//.........这里部分代码省略.........
break;
case Instruction::Store:
{
Value * sval = inst->getOperand(0);
Value * sadd = inst->getOperand(1);
addPtrTo(wrapValue(sadd), wrapValue(sval));
}
break;
case Instruction::GetElementPtr:
{
makeAlias(wrapValue(inst), handle_gep((GEPOperator*) inst));
}
break;
// conversion operations
case Instruction::Trunc:
case Instruction::ZExt:
case Instruction::SExt:
case Instruction::FPTrunc:
case Instruction::FPExt:
case Instruction::FPToUI:
case Instruction::FPToSI:
case Instruction::UIToFP:
case Instruction::SIToFP:
case Instruction::BitCast:
case Instruction::PtrToInt:
case Instruction::IntToPtr:
{
Value * itpv = inst->getOperand(0);
makeAlias(wrapValue(inst), wrapValue(itpv));
}
break;
// other operations
case Instruction::Invoke: // invoke is a terminal operation
{
InvokeInst * invoke = (InvokeInst*) inst;
LandingPadInst* lpd = invoke->getLandingPadInst();
parent_func->addLandingPad(invoke, lpd);
Value * cv = invoke->getCalledValue();
vector<Value*> args;
for (unsigned i = 0; i < invoke->getNumArgOperands(); i++) {
args.push_back(invoke->getArgOperand(i));
}
this->handle_invoke_call_inst(invoke, cv, &args, parent_func);
}
break;
case Instruction::Call:
{
CallInst * callinst = (CallInst*) inst;
if (callinst->isInlineAsm()) {
break;
}
Value * cv = callinst->getCalledValue();
vector<Value*> args;
for (unsigned i = 0; i < callinst->getNumArgOperands(); i++) {
args.push_back(callinst->getArgOperand(i));
}
this->handle_invoke_call_inst(callinst, cv, &args, parent_func);
}
break;
case Instruction::PHI:
{
PHINode *phi = (PHINode *) inst;
int nums = phi->getNumIncomingValues();
for (int i = 0; i < nums; i++) {
Value * p = phi->getIncomingValue(i);
makeAlias(wrapValue(inst), wrapValue(p));
}
}
break;
case Instruction::Select:
{
Value *first = ((SelectInst*) inst)->getTrueValue();
Value *second = ((SelectInst*) inst)->getFalseValue();
makeAlias(wrapValue(inst), wrapValue(first));
makeAlias(wrapValue(inst), wrapValue(second));
}
break;
case Instruction::VAArg:
{
parent_func->addVAArg(inst);
DyckVertex* vaarg = wrapValue(inst);
Value * ptrVaarg = inst->getOperand(0);
addPtrTo(wrapValue(ptrVaarg), vaarg);
}
break;
case Instruction::LandingPad: // handled with invoke inst
case Instruction::ICmp:
case Instruction::FCmp:
default:
break;
}
}