* cfgloopmanip.c (duplicate_loop_to_header_edge): Cleanup profile
[official-gcc.git] / gcc / testsuite / jit.dg / test-error-return-within-void-function.c
blob1b0e9c839d295df9de58434a4953e248a55046ad
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:
12 void
13 test_fn ()
15 return 42;
18 and verify that the API complains about the return
19 of a value within a function with "void" return.
21 gcc_jit_type *void_type =
22 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
23 gcc_jit_type *int_type =
24 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
26 gcc_jit_function *test_fn =
27 gcc_jit_context_new_function (ctxt, NULL,
28 GCC_JIT_FUNCTION_EXPORTED,
29 void_type, /* "void" return */
30 "test_fn",
31 0, NULL,
32 0);
33 gcc_jit_block *block = gcc_jit_function_new_block (test_fn, NULL);
35 /* "return 42;" (i.e. non-void) */
36 gcc_jit_block_end_with_return (
37 block, NULL,
38 gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 42));
41 void
42 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
44 /* Ensure that the "return 42" leads to the API giving a NULL
45 result back. */
46 CHECK_VALUE (result, NULL);
48 /* Verify that the correct error message was emitted. */
49 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
50 "gcc_jit_block_end_with_return:"
51 " mismatching types: return of (int)42 (type: int)"
52 " in function test_fn (return type: void)");