jit: handle equality of function pointer types
[official-gcc.git] / gcc / testsuite / jit.dg / test-error-mismatching-types-in-call.c
blobe89c281699a0815b1f5e8757c6bac48242c7c1ee
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 struct foo;
15 extern void called_function (struct foo *ptr);
17 void
18 test_fn ()
20 struct foo f;
21 called_function (f);
24 and verify that we get a type error (foo * vs foo).
26 gcc_jit_type *void_type =
27 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
28 gcc_jit_struct *struct_foo =
29 gcc_jit_context_new_struct_type (ctxt, NULL, "foo", 0, NULL);
30 gcc_jit_type *foo_ptr =
31 gcc_jit_type_get_pointer (gcc_jit_struct_as_type (struct_foo));
32 gcc_jit_param *param =
33 gcc_jit_context_new_param (ctxt, NULL, foo_ptr, "ptr");
35 gcc_jit_function *called_function =
36 gcc_jit_context_new_function (ctxt, NULL,
37 GCC_JIT_FUNCTION_IMPORTED,
38 void_type,
39 "called_function",
40 1, &param,
41 0);
43 gcc_jit_function *test_fn =
44 gcc_jit_context_new_function (ctxt, NULL,
45 GCC_JIT_FUNCTION_EXPORTED,
46 void_type,
47 "test_fn",
48 0, NULL,
49 0);
50 gcc_jit_lvalue *f =
51 gcc_jit_function_new_local (
52 test_fn, NULL, gcc_jit_struct_as_type (struct_foo), "f");
54 gcc_jit_block *block = gcc_jit_function_new_block (test_fn, NULL);
56 gcc_jit_rvalue *arg = gcc_jit_lvalue_as_rvalue (f);
58 gcc_jit_block_add_eval (
59 block, NULL,
60 gcc_jit_context_new_call (
61 ctxt, NULL,
62 called_function,
63 1, &arg));
64 gcc_jit_block_end_with_void_return (block, NULL);
67 void
68 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
70 CHECK_VALUE (result, NULL);
72 /* Verify that the correct error message was emitted. */
73 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
74 "gcc_jit_context_new_call:"
75 " mismatching types for argument 1"
76 " of function \"called_function\":"
77 " assignment to param ptr (type: struct foo *)"
78 " from f (type: struct foo)");