gpt4 book ai didi

c++ - 如何检查 LLVM StoreInst 的目标是否为函数指针

转载 作者:行者123 更新时间:2023-11-30 03:38:36 41 4
gpt4 key购买 nike

如何检查 LLVM StoreInst 的存储目标是否为函数指针?

最佳答案

给定一个 LLVM 加载/存储指令,有两个单独的部分需要计算。首先,位置的类型是什么。其次,类型是否满足某些属性等。

if (StoreInst *si = dyn_cast<StoreInst>(&*I))
{
Value* v = si->getPointerOperand();
Type* ptrType = v->getType()->getPointerElementType();

现在,指针类型就是存储数据的类型。但我们想知道底层类型是否实际上是一个函数,从而使它成为一个函数指针(或指针指针等)。

    if (PointerType* pt = dyn_cast<PointerType>(ptrType))
{
do {
// The call to getTypeAtIndex has to be made on a composite type
// And needs explicitly an unsigned int, otherwise 0
// can ambiguously be NULL.
Type* pointedType = pt->getTypeAtIndex((unsigned int)0);
if (pointedType->isFunctionTy())
{
errs() << "Found the underlying function type\n";
break;
}

// This may be a pointer to a pointer to ...
ptrType = pointedType;
} while (pt = dyn_cast<PointerType>(ptrType));

此代码检测到以下存储 - store i8* (i8*)* @tFunc, i8* (i8*)** %8, align 8,它将指向函数 tFunc 的指针存储到另一个位置。

关于c++ - 如何检查 LLVM StoreInst 的目标是否为函数指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39485740/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com