Calling a function with bad signature, possible bug.


I'm having troubles with writing a pass. In my pass I've have created a function that has two parameters - both of type i8*. Initially I wrote this function in C, that I translated it into IR, and then by using llc -march=cpp I got it's implementation in cpp code that actually inserts IR instructions. Then, I inserted this cpp code in my pass.

And in some places of a program my pass inserts instrumentation that calls this function.

The problem I'm experiencing is very strange. I'm getting "Calling a function with bad signature", when my pass inserts a call to this function. But I don't have any problems with my pass if I run clang -emit-llvm -S, then llc and then gcc. With this approach I get a binary with my instrumentation inserted.

This line causes a problem - assert((i >= FTy->getNumParams() ||
            FTy->getParamType(i) == Args[i]->getType()) &&
           "Calling a function with a bad signature!");

I tried to get a dump of FTy->getParamType(i) and Args[i]->getType(), but I wasn't able to do it in gdb - everytime I create a breakpoint it just misses it. So I made the following:

      errs() << "\nparamtype end----------- \n";
      errs() << "\ngettype end ------------\n";
      errs() << i << "\ni------------------\n";
      errs() << FTy->getNumParams() << "\ngetnumparams end ------------\n";
      errs() << "assert " << (FTy->getParamType(i) == Args[i]->getType()) << "\n";
      assert((i >= FTy->getNumParams() ||
            FTy->getParamType(i) == Args[i]->getType()) &&
           "Calling a function with a bad signature!");

I know, this is a bizzare, but still. The output I've got:

paramtype end-----------
gettype end ------------
getnumparams end ------------
assert 0

You see - totally unexplainable: FTy->getParamType(i) and Args[i]->getType() are the same, but assertion still fails.

Can anybody comment on this.


I found the source of my problem. The problem happened because type of the parameter I called the function with was declared in a different context (getGlobalContext()) comparing to function type (mod->getContext()).