本文整理汇总了C++中ConstantExpr::isCast方法的典型用法代码示例。如果您正苦于以下问题:C++ ConstantExpr::isCast方法的具体用法?C++ ConstantExpr::isCast怎么用?C++ ConstantExpr::isCast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConstantExpr
的用法示例。
在下文中一共展示了ConstantExpr::isCast方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PatchDtorFunctions
void ControlFlowIntegrity::PatchDtorFunctions(void) {
GlobalVariable *global_dtors = _M.getNamedGlobal("llvm.global_dtors");
// check for dtor section
if (!global_dtors || !global_dtors->getOperand(0)) {
return;
}
Constant *c = global_dtors->getInitializer();
if (!c)
report_fatal_error("llvm.global_dtors without initializer!", false);
ConstantArray *CA = dyn_cast<ConstantArray>(c);
if (!CA)
report_fatal_error("Cast to ConstantArray failed", true);
for (Value *Op : ValueOpRange(*CA)) {
ConstantStruct *CS = dyn_cast<ConstantStruct>(Op);
if (!CS)
report_fatal_error("Cast to ConstantStruct failed", true);
Constant *FP = CS->getOperand(1);
if (FP->isNullValue())
break; // found a NULL termintator, stop here
Function *F = dyn_cast_or_null<Function>(FP);
if (F == NULL) {
// Strip off constant expression cast
ConstantExpr *CE = dyn_cast<ConstantExpr>(FP);
if (!CE)
report_fatal_error("Cast to ConstantExpr failed", true);
if (CE->isCast()) {
FP = CE->getOperand(0);
}
F = dyn_cast_or_null<Function>(FP);
}
if (!F)
report_fatal_error("Cast to Function failed", true);
// set visibility to hidden (do not export), unless it is already
// local (for ex. static), in which case we have to make it non-static
if (F->hasLocalLinkage()) {
F->setLinkage(llvm::GlobalValue::ExternalLinkage);
}
F->setVisibility(GlobalValue::HiddenVisibility);
_FiniFunctions.insert(F->getName());
}
if (global_dtors->getNumUses() > 0)
report_fatal_error("llvm.global_dtors uses count is > 0!", false);
global_dtors->removeFromParent();
}
示例2: ParseAnnotations
void ControlFlowIntegrity::ParseAnnotations(void) {
GlobalVariable *global_ctors = _M.getNamedGlobal("llvm.global.annotations");
// check for ctor section
if (!global_ctors || !global_ctors->getOperand(0)) {
return;
}
Constant *c = global_ctors->getInitializer();
if (!c)
report_fatal_error("llvm.global.annotations without initializer!", false);
ConstantArray *CA = dyn_cast<ConstantArray>(c);
if (!CA)
report_fatal_error("Cast to ConstantArray failed", true);
for (Value *Op : ValueOpRange(*CA)) {
ConstantStruct *CS = dyn_cast<ConstantStruct>(Op);
if (!CS)
report_fatal_error("Cast to ConstantStruct failed", true);
Constant *FP = CS->getOperand(0);
if (FP->isNullValue())
break; // found a NULL termintator, stop here
ConstantExpr *CE;
Function *F = dyn_cast_or_null<Function>(FP);
if (F == NULL) {
// Strip off constant expression cast
CE = dyn_cast<ConstantExpr>(FP);
if (!CE)
report_fatal_error("Cast to ConstantExpr failed", true);
if (CE->isCast()) {
FP = CE->getOperand(0);
F = dyn_cast_or_null<Function>(FP);
}
}
if (!F)
report_fatal_error("Cast to Function failed", true);
Constant *SP = CS->getOperand(1);
if (SP->isNullValue())
break; // found a NULL termintator, stop here
// Strip off constant expression cast
CE = dyn_cast<ConstantExpr>(SP);
if (!CE)
report_fatal_error("Cast to ConstantExpr failed", true);
if (CE->isCast()) {
SP = CE->getOperand(0);
}
Value *V = SP->getOperand(0);
GlobalVariable *GV = dyn_cast_or_null<GlobalVariable>(V);
if (!GV)
report_fatal_error("Cast to GlobalVariable failed", false);
assert(GV && "cast to GlobalVariable failed");
Constant *cval = GV->getInitializer();
const StringRef s = (cast<ConstantDataArray>(cval))->getAsCString();
if (s == ANNOTATION_IGNORE_BLOCK) {
_IgnoredBlocksFunctions.insert(F->getName());
}
}
if (global_ctors->getNumUses() > 0)
report_fatal_error("llvm.global.annotations uses count is > 0", false);
}