mardi 31 mars 2020

Analyze store instruction consisting inttoptr in LLVM

I am trying to analyze a byte code consisting of a store instruction with inttoptr. I am having trouble to detect whether a store instruction has the inttoptr value as the value operand (3rd instruction in the following code in entry BB). My opcode looks like the following:

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
}

I am trying to analyze the store instruction and trying to find whether inttoptr is in a store instruction by using classof method and with dyn_cast like the following code:

  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";
  }

It seems I am not being able to detect inttoptr with any of the methods. I know the byte code is not creating a separate instruction for the inttoptr but it is merging with the store instruction. It would be really nice if anyone points me what I am missing and how I can detect the inttoptr in a store instruction.

Aucun commentaire:

Enregistrer un commentaire