本文整理汇总了C++中GlobalObject::isNullValue方法的典型用法代码示例。如果您正苦于以下问题:C++ GlobalObject::isNullValue方法的具体用法?C++ GlobalObject::isNullValue怎么用?C++ GlobalObject::isNullValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GlobalObject
的用法示例。
在下文中一共展示了GlobalObject::isNullValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestFuncs
bool ReduceCrashingFunctions::TestFuncs(std::vector<Function *> &Funcs) {
// If main isn't present, claim there is no problem.
if (KeepMain && !is_contained(Funcs, BD.getProgram()->getFunction("main")))
return false;
// Clone the program to try hacking it apart...
ValueToValueMapTy VMap;
Module *M = CloneModule(BD.getProgram(), VMap).release();
// Convert list to set for fast lookup...
std::set<Function *> Functions;
for (unsigned i = 0, e = Funcs.size(); i != e; ++i) {
Function *CMF = cast<Function>(VMap[Funcs[i]]);
assert(CMF && "Function not in module?!");
assert(CMF->getFunctionType() == Funcs[i]->getFunctionType() && "wrong ty");
assert(CMF->getName() == Funcs[i]->getName() && "wrong name");
Functions.insert(CMF);
}
outs() << "Checking for crash with only these functions: ";
PrintFunctionList(Funcs);
outs() << ": ";
if (!ReplaceFuncsWithNull) {
// Loop over and delete any functions which we aren't supposed to be playing
// with...
for (Function &I : *M)
if (!I.isDeclaration() && !Functions.count(&I))
DeleteFunctionBody(&I);
} else {
std::vector<GlobalValue *> ToRemove;
// First, remove aliases to functions we're about to purge.
for (GlobalAlias &Alias : M->aliases()) {
GlobalObject *Root = Alias.getBaseObject();
Function *F = dyn_cast_or_null<Function>(Root);
if (F) {
if (Functions.count(F))
// We're keeping this function.
continue;
} else if (Root->isNullValue()) {
// This referenced a globalalias that we've already replaced,
// so we still need to replace this alias.
} else if (!F) {
// Not a function, therefore not something we mess with.
continue;
}
PointerType *Ty = cast<PointerType>(Alias.getType());
Constant *Replacement = ConstantPointerNull::get(Ty);
Alias.replaceAllUsesWith(Replacement);
ToRemove.push_back(&Alias);
}
for (Function &I : *M) {
if (!I.isDeclaration() && !Functions.count(&I)) {
PointerType *Ty = cast<PointerType>(I.getType());
Constant *Replacement = ConstantPointerNull::get(Ty);
I.replaceAllUsesWith(Replacement);
ToRemove.push_back(&I);
}
}
for (auto *F : ToRemove) {
F->eraseFromParent();
}
// Finally, remove any null members from any global intrinsic.
RemoveFunctionReferences(M, "llvm.used");
RemoveFunctionReferences(M, "llvm.compiler.used");
}
// Try running the hacked up program...
if (TestFn(BD, M)) {
BD.setNewProgram(M); // It crashed, keep the trimmed version...
// Make sure to use function pointers that point into the now-current
// module.
Funcs.assign(Functions.begin(), Functions.end());
return true;
}
delete M;
return false;
}