jit: New API entrypoint: gcc_jit_context_get_last_error
[official-gcc.git] / gcc / testsuite / jit.dg / test-error-null-passed-to-api.c
blob2fab453c1a0d0bc0f7c9db25dc4eebf192ec1232
1 #include <stdlib.h>
2 #include <stdio.h>
4 #include "libgccjit.h"
6 #include "harness.h"
8 void
9 create_code (gcc_jit_context *ctxt, void *user_data)
11 /* Trigger an API error by passing bad data. */
12 gcc_jit_context_new_function (ctxt, NULL,
13 GCC_JIT_FUNCTION_EXPORTED,
14 NULL, /* error: this must be non-NULL */
15 "hello_world",
16 0, NULL,
17 0);
20 void
21 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
23 /* Ensure that the bad API usage prevents the API giving a bogus
24 result back. */
25 CHECK_VALUE (result, NULL);
27 /* Verify that the correct error message was emitted. */
28 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
29 "gcc_jit_context_new_function: NULL return_type");
30 CHECK_STRING_VALUE (gcc_jit_context_get_last_error (ctxt),
31 "gcc_jit_context_new_function: NULL return_type");