error handling in GCCJIT?
David Malcolm
dmalcolm@redhat.com
Thu Jan 1 00:00:00 GMT 2015
On Thu, 2015-07-09 at 12:51 +0200, Basile Starynkevitch wrote:
> Hello all,
>
> What is the design philosophy of GCCJIT w.r.t. errors? Is the calling
> application supposed to avoid as much as possible any errors,
Yes.
> or on
> the contrary can it rely on GCCJIT error checking and not do the
> checking itself?
If an error occurs, that gcc_jit_context * effectively becomes unusable:
it attempts to gracefully continue without crashing, but you won't get
code out at the end.
The idea is that all errors need to be fixed at development time, but to
fail gracefully in production, without needing lots of run-time
error-checking in client code at each callsite,
FWIW, this is a somewhat similar approach to how OpenGL handles errors.
Most of this error-checking occurs in gcc/jit/libgccjit.c.
> For examples:
>
> should the caller check that every case in a switch statement
> is unique and non-overlapping for case ranges,
Yes, the client code needs to ensure that those requirements hold...
> or should it leave that to GCCJIT?
If the requirements don't hold, then the call to
gcc_jit_block_end_with_switch will fail with an error, and the
gcc_jit_context * won't generate any code.
See e.g.:
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/testsuite/jit.dg/test-error-gcc_jit_block_end_with_switch-overlapping-ranges.c
> should the caller check that arithmetic operations are only done on
> numeric variables I guess that gcc_jit_context_new_binary_op with
> GCC_JIT_BINARY_OP_PLUS of two pointer variables is a non-sense, as it
> is in C.
Yes, the caller should enforce this requirement...
> Or is that checked (and does gcc_jit_context_new_binary_op
> returns NULL in that case)?
It looks like gcc_jit_context_new_binary_op is missing error-handling
for that case. That's a bug.
> what happens (and when?) if gcc_jit_block_end_with_conditional is
> given a non-boolean boolval?
It will fail with an error; c.f.:
RETURN_IF_FAIL_PRINTF2 (
is_bool (boolval), ctxt, loc,
"%s (type: %s) is not of boolean type ",
boolval->get_debug_string (),
boolval->get_type ()->get_debug_string ());
> etc....
>
> PS. Perhaps the documentation might tell more about this...
See:
https://gcc.gnu.org/onlinedocs/jit/topics/contexts.html#error-handling
and
https://gcc.gnu.org/onlinedocs/jit/internals/index.html#design-notes
Please file bugs about any missing error-checking you see, or missing
documentation.
More information about the Jit
mailing list