* gcc-interface/trans.c (node_has_volatile_full_access) <N_Identifier>:
[official-gcc.git] / gcc / testsuite / jit.dg / test-error-local-used-from-other-function.c
blobfac47c853e84c1d90b6cdfe884fa102ad3034652
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 ()
16 int i;
19 int
20 fn_two ()
22 return i;
25 and verify that the API complains about the use of the local
26 from the other function. */
27 gcc_jit_type *void_type =
28 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
29 gcc_jit_type *int_type =
30 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
32 gcc_jit_function *fn_one =
33 gcc_jit_context_new_function (ctxt, NULL,
34 GCC_JIT_FUNCTION_EXPORTED,
35 void_type,
36 "fn_one",
37 0, NULL,
38 0);
39 gcc_jit_lvalue *local =
40 gcc_jit_function_new_local (fn_one, NULL, int_type, "i");
42 gcc_jit_function *fn_two =
43 gcc_jit_context_new_function (ctxt, NULL,
44 GCC_JIT_FUNCTION_EXPORTED,
45 int_type,
46 "fn_two",
47 0, NULL,
48 0);
50 gcc_jit_block *block = gcc_jit_function_new_block (fn_two, NULL);
51 /* "return i;", using local i from the wrong function. */
52 gcc_jit_block_end_with_return (block,
53 NULL,
54 gcc_jit_lvalue_as_rvalue (local));
57 void
58 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
60 CHECK_VALUE (result, NULL);
62 /* Verify that the correct error message was emitted. */
63 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
64 ("gcc_jit_block_end_with_return:"
65 " rvalue i (type: int)"
66 " has scope limited to function fn_one"
67 " but was used within function fn_two"
68 " (in statement: return i;)"));