comparison gcc/testsuite/jit.dg/test-error-call-through-ptr-with-non-pointer.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 #include <stdlib.h>
2 #include <stdio.h>
3
4 #include "libgccjit.h"
5
6 #include "harness.h"
7
8 void
9 create_code (gcc_jit_context *ctxt, void *user_data)
10 {
11 /* Let's try to inject the equivalent of:
12
13 void
14 test_fn ()
15 {
16 ((some_unspecified_fn_ptr_type)42) (43);
17 }
18
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);
25
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);
38
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);
50 }
51
52 void
53 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
54 {
55 CHECK_VALUE (result, NULL);
56
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"));
61 }
62