在LLVM中分析包含inttoptr的存储指令

问题描述 投票:0回答:1

我正在尝试使用inttoptr分析由存储指令组成的字节码。我在检测存储指令是否具有inttoptr值作为值操作数时遇到麻烦(条目BB中以下代码中的第三条指令)。我的操作码如下所示:

define dso_local i32 @test(i32* %p) #0 {
entry:
  %p.addr = alloca i32*, align 8
  store i32* %p, i32** %p.addr, align 8
  store i32* inttoptr (i64 1000 to i32*), i32** %p.addr, align 8
  %0 = load i32*, i32** %p.addr, align 8
  %1 = load i32, i32* %0, align 4
  ret i32 %1
}

我正在尝试分析存储指令,并尝试通过使用classof方法并使用dyn_cast来查找inttoptr是否在存储指令中,如以下代码:

  StoreInst *store = dyn_cast<StoreInst>(I);
  Value *vv = store->getValueOperand();
  Value *vp = store->getPointerOperand();
  if(IntToPtrInst::classof(vv)){
    outs() << "Inttoptr found\n";
  }
  if(Instruction *inp = dyn_cast<IntToPtrInst>(vv)){
    outs() << "Inttoptr found\n";
  }

似乎我无法使用任何方法检测inttoptr。我知道字节码不会为inttoptr创建单独的指令,但是它正在与存储指令合并。如果有人指出我所缺少的内容以及如何在存储指令中检测到inttoptr,那真是太好了。

c++11 llvm clang++ llvm-ir llvm-c++-api
1个回答
0
投票

您感兴趣的演员表不是指令,而是a constant cast from the constant integer 1000 to a pointer。您可以使用isa<ConstantExpr>(foo->getPointerOperand()) && cast<ConstantExpr>(foo->getPointerOperand())->getOpcode() == ConstantExpr::IntToPtrCast之类的测试来检测到它,但是我从内存中键入了该代码,并且肯定有错字。

当您阅读IR时,指令总是在自己的行上,而常量作为参数或初始化程序是内联的,甚至是使用ConstantExpr生成的相当复杂的常量。

© www.soinside.com 2019 - 2024. All rights reserved.