1 #include <math.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 
5 #include "libgccjit.h"
6 
7 #include "harness.h"
8 
9 void
create_code(gcc_jit_context * ctxt,void * user_data)10 create_code (gcc_jit_context *ctxt, void *user_data)
11 {
12   /* Let's try to inject the equivalent of:
13        void
14        test_fn ()
15        {
16 	 return;
17 	 return;
18        }
19   */
20   gcc_jit_type *void_t =
21     gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
22 
23   /* Build the test_fn.  */
24   gcc_jit_function *test_fn =
25     gcc_jit_context_new_function (ctxt, NULL,
26                                   GCC_JIT_FUNCTION_EXPORTED,
27                                   void_t,
28                                   "test_fn",
29                                   0, NULL,
30                                   0);
31   gcc_jit_block *initial =
32     gcc_jit_function_new_block (test_fn, "initial");
33 
34   gcc_jit_block_end_with_void_return (initial, NULL);
35   /* Error: "initial" has already been terminated.  */
36   gcc_jit_block_end_with_void_return (initial, NULL);
37 }
38 
39 void
verify_code(gcc_jit_context * ctxt,gcc_jit_result * result)40 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
41 {
42   CHECK_VALUE (result, NULL);
43 
44   CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
45 		      "gcc_jit_block_end_with_void_return:"
46 		      " adding to terminated block:"
47 		      " initial (already terminated by: return;)");
48 }
49