LLVM Cannot find getelementptr command

I have this byte code snippet:

define void @setGlobal(i32 %a) #0 {
entry:
  %a.addr = alloca i32, align 4
  store i32 %a, i32* %a.addr, align 4
  %0 = load i32* %a.addr, align 4
  store i32 %0, i32* @Global, align 4
  %1 = load i32* %a.addr, align 4
  store i32 %1, i32* getelementptr inbounds ([5 x i32]* @GlobalVec, i32 0, i64 0), align 4
  store i32 2, i32* getelementptr inbounds ([5 x i32]* @GlobalVec, i32 0, i64 2), align 4
  ret void
}

I use this code to find getelementptr from "store i32% 1, i32 * getelementptr inbounds ([5 x i32] * @GlobalVec, i32 0, i64 0), align 4":

for (Module::iterator F = p_Module.begin(), endF = p_Module.end(); F != endF; ++F) {

        for (Function::iterator BB = F->begin(), endBB = F->end(); BB != endBB; ++BB) {

            for (BasicBlock::iterator I = BB->begin(), endI = BB->end(); I
                    != endI; ++I) {
                if (StoreInst* SI = dyn_cast<StoreInst>(I)) {
                    if (Instruction *gep = dyn_cast<Instruction>(SI->getOperand(1)))
                    {
                        if (gep->getOpcode() == Instruction::GetElementPtr)
                        {
                            //do something
                        }

                    }

                }

            }
        }
}

This code cannot find getelementptr. What am I doing wrong?

+4
source share
1 answer

There are no instructions in your code snippet getelementptr, so you cannot find them.

Two cases that look like instructions getelementptrare actually constant expressions - a check mark means that they are displayed as part of another command ( store), which you cannot do with regular instructions.

, , type GetElementPtrConstantExpr, GetElementPtrInst.

+3

Source: https://habr.com/ru/post/1527123/


All Articles