2018-02-09 Sebastian Perta <sebastian.perta@renesas.com>
[official-gcc.git] / gcc / testsuite / jit.dg / test-error-call-through-ptr-with-not-enough-args.c
blob3e160f4c441c0edfa3dc2e3be462a6c06d720927
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 /* Let's try to inject the equivalent of:
13 void
14 test_caller (void (*some_fn_ptr) (int p))
16 called_function (); // missing arg
19 and verify that the API complains about the missing argument.
21 gcc_jit_type *void_type =
22 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
23 gcc_jit_type *int_type =
24 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
26 /* Build the function ptr type. */
27 gcc_jit_type *fn_ptr_type =
28 gcc_jit_context_new_function_ptr_type (ctxt, NULL,
29 void_type,
30 1, &int_type, 0);
32 /* Build the test_fn. */
33 gcc_jit_param *param_fn_ptr =
34 gcc_jit_context_new_param (ctxt, NULL, fn_ptr_type, "some_fn_ptr");
36 gcc_jit_function *test_fn =
37 gcc_jit_context_new_function (ctxt, NULL,
38 GCC_JIT_FUNCTION_EXPORTED,
39 void_type,
40 "test_caller",
41 1, &param_fn_ptr,
42 0);
44 gcc_jit_block *block = gcc_jit_function_new_block (test_fn, NULL);
45 /* called_function (); */
46 gcc_jit_block_add_eval (
47 block, NULL,
48 gcc_jit_context_new_call_through_ptr (
49 ctxt,
50 NULL,
51 gcc_jit_param_as_rvalue (param_fn_ptr),
52 0, NULL));
53 /* the above has not enough args. */
54 gcc_jit_block_end_with_void_return (block, NULL);
57 void
58 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
60 /* Ensure that mismatching arg count leads to the API giving a NULL
61 result back. */
62 CHECK_VALUE (result, NULL);
64 /* Verify that the correct error message was emitted. */
65 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
66 ("gcc_jit_context_new_call_through_ptr:"
67 " not enough arguments to fn_ptr: some_fn_ptr"
68 " (got 0 args, expected 1)"));