111
|
1 #include <stdlib.h>
|
|
2 #include <stdio.h>
|
|
3
|
|
4 #include "libgccjit.h"
|
|
5
|
|
6 #include "harness.h"
|
|
7
|
|
8 #ifdef __cplusplus
|
|
9 extern "C" {
|
|
10 #endif
|
|
11
|
|
12 extern void
|
|
13 called_function (void *ptr);
|
|
14
|
|
15 #ifdef __cplusplus
|
|
16 }
|
|
17 #endif
|
|
18
|
|
19 void
|
|
20 create_code (gcc_jit_context *ctxt, void *user_data)
|
|
21 {
|
|
22 /* Verify that we get an error (rather than a crash)
|
|
23 if the client code reuses a gcc_jit_param * for
|
|
24 two different functions. */
|
|
25 gcc_jit_type *void_type =
|
|
26 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
|
|
27 gcc_jit_type *int_type =
|
|
28 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
|
|
29
|
|
30 /* Create a param. */
|
|
31 gcc_jit_param *param =
|
|
32 gcc_jit_context_new_param (ctxt, NULL, int_type, "i");
|
|
33
|
|
34 /* Try to use it for two different functions. */
|
|
35 gcc_jit_context_new_function (ctxt, NULL,
|
|
36 GCC_JIT_FUNCTION_EXPORTED,
|
|
37 void_type,
|
|
38 "fn_one",
|
|
39 1, ¶m,
|
|
40 0);
|
|
41 gcc_jit_context_new_function (ctxt, NULL,
|
|
42 GCC_JIT_FUNCTION_EXPORTED,
|
|
43 void_type,
|
|
44 "fn_two",
|
|
45 1, ¶m,
|
|
46 0);
|
|
47 }
|
|
48
|
|
49 void
|
|
50 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
|
|
51 {
|
|
52 CHECK_VALUE (result, NULL);
|
|
53
|
|
54 /* Verify that the correct error message was emitted. */
|
|
55 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
|
|
56 ("gcc_jit_context_new_function:"
|
|
57 " parameter 0 \"i\" (type: int)"
|
|
58 " for function fn_two"
|
|
59 " was already used for function fn_one"))
|
|
60 }
|
|
61
|