How to insert a self-written function to a piece of programme

Hi all,
I wrote a function pass. In the pass, it ran through all the instruction that call to functions. When arriving at the exact function that I m interested in, it would insert a self-made function.

Now I’ve finished the pass, the compilation is successful. The pass can find the function I like and can insert the CallInst to call my check function. BUT, when running the pass, it breaks down. The Diagnose is as follow,

Hi 15102925731,

*Referencing function in another module!
%CallCheck = call i32 @check()
Broken module found, compilation aborted!*

*//Create a function prototype exactly like "int check()", then create a call
instruction to that function.*
Module * M;
LLVMContext Context;
FunctionType *STy=FunctionType::get(Type::getInt32Ty(Context), false);
Function *check = Function::Create(STy, Function::InternalLinkage, "check" ,M);

So here M is passed in uninitialized; same with Context?

Ciao, Duncan.