2.4.1.7 Function calls

C Function: gcc_jit_rvalue * gcc_jit_context_new_call (gcc_jit_context *ctxt, gcc_jit_location *loc, gcc_jit_function *func, int numargs, gcc_jit_rvalue **args)

Given a function and the given table of argument rvalues, construct a call to the function, with the result as an rvalue.

Note: gcc_jit_context_new_call() merely builds a gcc_jit_rvalue i.e. an expression that can be evaluated, perhaps as part of a more complicated expression. The call `won’t' happen unless you add a statement to a function that evaluates the expression.

For example, if you want to call a function and discard the result (or to call a function with void return type), use gcc_jit_block_add_eval():

/* Add "(void)printf (arg0, arg1);".  */
gcc_jit_block_add_eval (
  block, NULL,
  gcc_jit_context_new_call (
    ctxt,
    NULL,
    printf_func,
    2, args));
C Function: gcc_jit_rvalue * gcc_jit_context_new_call_through_ptr (gcc_jit_context *ctxt, gcc_jit_location *loc, gcc_jit_rvalue *fn_ptr, int numargs, gcc_jit_rvalue **args)

Given an rvalue of function pointer type (e.g. from gcc_jit_context_new_function_ptr_type()), and the given table of argument rvalues, construct a call to the function pointer, with the result as an rvalue.

Note: The same caveat as for gcc_jit_context_new_call() applies.

C Function: void gcc_jit_rvalue_set_bool_require_tail_call (gcc_jit_rvalue *call, int require_tail_call)

Given an gcc_jit_rvalue for a call created through gcc_jit_context_new_call() or gcc_jit_context_new_call_through_ptr(), mark/clear the call as needing tail-call optimization. The optimizer will attempt to optimize the call into a jump instruction; if it is unable to do do, an error will be emitted.

This may be useful when implementing functions that use the continuation-passing style (e.g. for functional programming languages), in which every function “returns” by calling a “continuation” function pointer. This call must be guaranteed to be implemented as a jump, otherwise the program could consume an arbitrary amount of stack space as it executed.

This entrypoint was added in LIBGCCJIT_ABI_6; you can test for its presence using

#ifdef LIBGCCJIT_HAVE_gcc_jit_rvalue_set_bool_require_tail_call