annotate gcc/testsuite/jit.dg/test-error-call-through-ptr-with-mismatching-args.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 #include <stdlib.h>
kono
parents:
diff changeset
2 #include <stdio.h>
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 #include "libgccjit.h"
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 #include "harness.h"
kono
parents:
diff changeset
7
kono
parents:
diff changeset
8 void
kono
parents:
diff changeset
9 create_code (gcc_jit_context *ctxt, void *user_data)
kono
parents:
diff changeset
10 {
kono
parents:
diff changeset
11 /* Let's try to inject the equivalent of:
kono
parents:
diff changeset
12
kono
parents:
diff changeset
13 void
kono
parents:
diff changeset
14 test_fn (void (*some_fn_ptr) (void *))
kono
parents:
diff changeset
15 {
kono
parents:
diff changeset
16 some_fn_ptr (42);
kono
parents:
diff changeset
17 }
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19 and verify that the API complains about the mismatching argument
kono
parents:
diff changeset
20 type ("int" vs "void *"). */
kono
parents:
diff changeset
21 gcc_jit_type *void_type =
kono
parents:
diff changeset
22 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
kono
parents:
diff changeset
23 gcc_jit_type *void_ptr_type =
kono
parents:
diff changeset
24 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID_PTR);
kono
parents:
diff changeset
25 gcc_jit_type *int_type =
kono
parents:
diff changeset
26 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 /* Build the function ptr type. */
kono
parents:
diff changeset
29 gcc_jit_type *fn_ptr_type =
kono
parents:
diff changeset
30 gcc_jit_context_new_function_ptr_type (ctxt, NULL,
kono
parents:
diff changeset
31 void_type,
kono
parents:
diff changeset
32 1, &void_ptr_type, 0);
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 /* Build the test_fn. */
kono
parents:
diff changeset
35 gcc_jit_param *param_fn_ptr =
kono
parents:
diff changeset
36 gcc_jit_context_new_param (ctxt, NULL, fn_ptr_type, "some_fn_ptr");
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 gcc_jit_function *test_fn =
kono
parents:
diff changeset
39 gcc_jit_context_new_function (ctxt, NULL,
kono
parents:
diff changeset
40 GCC_JIT_FUNCTION_EXPORTED,
kono
parents:
diff changeset
41 void_type,
kono
parents:
diff changeset
42 "test_fn",
kono
parents:
diff changeset
43 1, &param_fn_ptr,
kono
parents:
diff changeset
44 0);
kono
parents:
diff changeset
45 /* some_fn_ptr (42); */
kono
parents:
diff changeset
46 gcc_jit_rvalue *arg =
kono
parents:
diff changeset
47 gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 42);
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 gcc_jit_block *block = gcc_jit_function_new_block (test_fn, NULL);
kono
parents:
diff changeset
50 gcc_jit_block_add_eval (
kono
parents:
diff changeset
51 block, NULL,
kono
parents:
diff changeset
52 gcc_jit_context_new_call_through_ptr (
kono
parents:
diff changeset
53 ctxt,
kono
parents:
diff changeset
54 NULL,
kono
parents:
diff changeset
55 gcc_jit_param_as_rvalue (param_fn_ptr),
kono
parents:
diff changeset
56 1, &arg));
kono
parents:
diff changeset
57 /* the above has the wrong type for argument 1. */
kono
parents:
diff changeset
58 gcc_jit_block_end_with_void_return (block, NULL);
kono
parents:
diff changeset
59 }
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 void
kono
parents:
diff changeset
62 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
kono
parents:
diff changeset
63 {
kono
parents:
diff changeset
64 CHECK_VALUE (result, NULL);
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 /* Verify that the correct error message was emitted. */
kono
parents:
diff changeset
67 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
kono
parents:
diff changeset
68 ("gcc_jit_context_new_call_through_ptr:"
kono
parents:
diff changeset
69 " mismatching types for argument 1 of fn_ptr:"
kono
parents:
diff changeset
70 " some_fn_ptr:"
kono
parents:
diff changeset
71 " assignment to param 1 (type: void *)"
kono
parents:
diff changeset
72 " from (int)42 (type: int)"));
kono
parents:
diff changeset
73 }
kono
parents:
diff changeset
74