[LLVMdev] Referring to an argument in another function

Scott Ricketts sricketts at maxentric.com
Thu Jun 18 10:13:43 PDT 2009


I would like to instrument certain function calls with a function call
of my own that takes some of the same arguments. For example, I would
like to instrument calls to free with some function foo, so the C code
would look like:

foo(myarg1, myarg2, ptr);
free(ptr);

The problem occurs when I grab the arg from the free function and try
to pass it to foo...

  if (isCallToFree(&I)) {
    Value* P;
    if (Function *F = I.getCalledFunction()) {
      Function::arg_iterator ait = F->arg_begin();
      if (ait) {
        P = &(*ait);
      }
      createCallInst(mem_fcall, &I, 3, getOpcodeValue(I),
                     getInstrIDValue(), P);
    }
  }

createCallInst is my own wrapper. The error thrown during the pass is:

"Referring to an argument in another function!"

Any suggestions?

Thanks,
Scott



More information about the llvm-dev mailing list