1 #include <stdlib.h>
2 #include <stdio.h>
3 
4 #include "libgccjit.h"
5 
6 #include "harness.h"
7 
8 void
create_code(gcc_jit_context * ctxt,void * user_data)9 create_code (gcc_jit_context *ctxt, void *user_data)
10 {
11   /* Verify that we get an error (rather than a crash)
12      if the client code reuses a gcc_jit_param * within
13      a function.  */
14   gcc_jit_type *void_type =
15     gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
16   gcc_jit_type *int_type =
17     gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
18 
19   /* Create a param.  */
20   gcc_jit_param *param =
21     gcc_jit_context_new_param (ctxt, NULL, int_type, "i");
22 
23   /* Try to use it twice when creating "fn".  */
24   gcc_jit_param *params[2];
25   params[0] = param;
26   params[1] = param;
27 
28   gcc_jit_context_new_function (ctxt, NULL,
29 				GCC_JIT_FUNCTION_IMPORTED,
30 				void_type,
31 				"fn",
32 				2, params,
33 				0);
34 }
35 
36 void
verify_code(gcc_jit_context * ctxt,gcc_jit_result * result)37 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
38 {
39   CHECK_VALUE (result, NULL);
40 
41   /* Verify that the correct error message was emitted.  */
42   CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
43 		      ("gcc_jit_context_new_function:"
44 		       " parameter i (type: int)"
45 		       " is used more than once when creating function"
46 		       " fn"))
47 }
48 
49