[LLVMdev] Self-referential function pointer

Duncan Sands baldrick at free.fr
Fri Jul 6 05:13:51 PDT 2012


Hi Cameron,

> I could use some advice on a special case of a function pointer as a formal
> argument. I would like the function pointer type to contain the actual signature
> of the function, i.e. not a pointer to var args function. This becomes an issue
> when I have a function which can take a pointer to itself as an argument... our
> terminology for this is "a recursive procedure". That is, of course, in a
> context where C-like recursion is not intrinsic to the language.
>
> With LLVM 2.9, the solution was to create an OpaqueType when creating the
> function type signature, use the OpaqueType as the function pointer argument
> type, and then finish the function type signature later. No problem.
>
> If I'm not mistaken, only StructType can be self-referential in LLVM 3.0 and
> beyond. So, is it not possible to have a self-referencing FunctionType, short of
> making the function pointer formals var args? Has anyone developed a solution
> for similar behavior?

no it's not possible, just use i8* or some other such artificial marker for the
parameter type.

Ciao, Duncan.



More information about the llvm-dev mailing list