* gcc-interface/decl.c (gnat_to_gnu_field): Do not set the alignment
[official-gcc.git] / gcc / testsuite / jit.dg / test-error-block-in-wrong-function.c
blob285fcb0b3dd71031253017c96a2b60803ed4d7e6
1 #include <math.h>
2 #include <stdlib.h>
3 #include <stdio.h>
5 #include "libgccjit.h"
7 #include "harness.h"
9 void
10 create_code (gcc_jit_context *ctxt, void *user_data)
12 /* Let's try to inject the equivalent of:
13 void
14 test_fn ()
16 goto label;
19 void
20 other_fn ()
22 label:
24 where the destination block is in another function.
26 gcc_jit_type *void_t =
27 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
29 /* Build the test_fn. */
30 gcc_jit_function *test_fn =
31 gcc_jit_context_new_function (ctxt, NULL,
32 GCC_JIT_FUNCTION_EXPORTED,
33 void_t,
34 "test_fn",
35 0, NULL,
36 0);
37 /* Build the other_fn. */
38 gcc_jit_function *other_fn =
39 gcc_jit_context_new_function (ctxt, NULL,
40 GCC_JIT_FUNCTION_EXPORTED,
41 void_t,
42 "other_fn",
43 0, NULL,
44 0);
46 gcc_jit_block *initial =
47 gcc_jit_function_new_block (test_fn, "initial");
48 gcc_jit_block *block_within_other_fn =
49 gcc_jit_function_new_block (other_fn, "block_within_other_fn");
51 gcc_jit_block_end_with_jump (initial, NULL, block_within_other_fn);
54 void
55 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
57 CHECK_VALUE (result, NULL);
59 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
60 "gcc_jit_block_end_with_jump:"
61 " target block is not in same function:"
62 " source block initial is in function test_fn"
63 " whereas target block block_within_other_fn"
64 " is in function other_fn");
65 /* Example of a testcase in which the last error != first error. */
66 CHECK_STRING_VALUE (gcc_jit_context_get_last_error (ctxt),
67 "unterminated block in other_fn: block_within_other_fn");