jit: handle equality of function pointer types
[official-gcc.git] / gcc / testsuite / jit.dg / test-error-param-used-from-other-function.c
blob84e898b1c952149cb9673a12ca546cd16ae96f0a
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 fn_one (int i)
18 int
19 fn_two ()
21 return i * 2;
24 and verify that the API complains about the use of the param
25 from the other function. */
26 gcc_jit_type *void_type =
27 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
28 gcc_jit_type *int_type =
29 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
31 gcc_jit_param *param =
32 gcc_jit_context_new_param (ctxt, NULL, int_type, "i");
34 gcc_jit_context_new_function (ctxt, NULL,
35 GCC_JIT_FUNCTION_EXPORTED,
36 void_type,
37 "fn_one",
38 1, &param,
39 0);
40 gcc_jit_function *fn_two =
41 gcc_jit_context_new_function (ctxt, NULL,
42 GCC_JIT_FUNCTION_EXPORTED,
43 int_type,
44 "fn_two",
45 0, NULL,
46 0);
48 gcc_jit_block *block = gcc_jit_function_new_block (fn_two, NULL);
49 /* "return i * 2;", using param i from the wrong function. */
50 gcc_jit_block_end_with_return (
51 block,
52 NULL,
53 gcc_jit_context_new_binary_op (
54 ctxt, NULL,
55 GCC_JIT_BINARY_OP_MULT,
56 int_type,
57 gcc_jit_param_as_rvalue (param),
58 gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 2)));
61 void
62 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
64 CHECK_VALUE (result, NULL);
66 /* Verify that the correct error message was emitted. */
67 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
68 ("gcc_jit_block_end_with_return:"
69 " rvalue i (type: int)"
70 " has scope limited to function fn_one"
71 " but was used within function fn_two"
72 " (in statement: return i * (int)2;)"));