Forward declaration of function LLVM
<p>I'm trying to use forward declaration of functions in LLVM, but I'm not able to do it... The reason for doing that is this error:</p>

<blockquote>
  <p>error: invalid forward reference to function 'f' with wrong type! "</p>
</blockquote>

<p>Right now I'm trying to do it with this code:</p>

<pre><code>std::vector&lt;Type *&gt; args_type = f-&gt;get_args_type();
Module* mod = get_module();
std::string struct_name("struct.");
struct_name.append(f-&gt;get_name());
Type* StructTy = mod-&gt;getTypeByName(struct_name);
if (!StructTy)  {
    StructTy = Type::getVoidTy(getGlobalContext());
}
FunctionType *ftype = FunctionType::get(StructTy, args_type, false);
//Function *func = Function::Create(ftype, GlobalValue::InternalLinkage, f-&gt;get_name(),  get_module());
Constant* c = mod-&gt;getOrInsertFunction(f-&gt;get_name(), ftype);
Function *func = cast&lt;Function&gt;(c);
</code></pre>

<p>But it does not show in the IR when I generate the code. When I create the function again using this same code shown above, it works. I wonder if it's because I insert a BasicBlock right after when I start insert things within the function. </p>

<p>Right now that's how it is my IR</p>

<pre><code>define internal void @main() {
entry:
    ...
}
define internal %struct.f @f(i32* %x) {
entry:
    ... 
}
</code></pre>

<p>I believe that putting an <code>declare %struct.f @f(i32*)</code> before the @main function would fix this issue, but I can't figure out how to do it...</p>

<p>Summary: I just want to create something with a  <code>declare</code> on top of the file, so I can use the <code>define</code> it later and start inserting instructions of the function</p>