2018-02-09 Sebastian Perta <sebastian.perta@renesas.com>
[official-gcc.git] / gcc / testsuite / jit.dg / test-error-call-through-ptr-with-non-pointer.c
blob8bb50d972038ea6d5301d6998a3c41aa2110ff69
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_fn ()
16 ((some_unspecified_fn_ptr_type)42) (43);
19 and verify that the API complains about the 42 not being a
20 function pointer. */
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 test_fn. */
27 gcc_jit_function *test_fn =
28 gcc_jit_context_new_function (ctxt, NULL,
29 GCC_JIT_FUNCTION_EXPORTED,
30 void_type,
31 "test_fn",
32 0, NULL,
33 0);
34 gcc_jit_rvalue *not_a_function =
35 gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 42);
36 gcc_jit_rvalue *arg =
37 gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 43);
39 /* ((some_unspecified_fn_ptr_type)42) (43); */
40 gcc_jit_block *block = gcc_jit_function_new_block (test_fn, NULL);
41 gcc_jit_block_add_eval (
42 block, NULL,
43 gcc_jit_context_new_call_through_ptr (
44 ctxt,
45 NULL,
46 /* This is not even a pointer, let alone a function pointer. */
47 not_a_function,
48 1, &arg));
49 gcc_jit_block_end_with_void_return (block, NULL);
52 void
53 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
55 CHECK_VALUE (result, NULL);
57 /* Verify that the correct error message was emitted. */
58 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
59 ("gcc_jit_context_new_call_through_ptr:"
60 " fn_ptr is not a ptr: (int)42 type: int"));