Debian Codegraph @

gcc/testsuite/jit.dg/test-pr95314-rvalue-reuse.c

raw
1 #include <libgccjit.h>
2 #include "harness.h"
3
4 void create_code (gcc_jit_context *ctxt, void *user_data)
5 {
6 gcc_jit_type *t_int = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
7 gcc_jit_type *t_void = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
8 gcc_jit_type *t_const_char_ptr
9 = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_CONST_CHAR_PTR);
10 gcc_jit_lvalue *global
11 = gcc_jit_context_new_global (ctxt, NULL, GCC_JIT_GLOBAL_INTERNAL,
12 t_const_char_ptr, "pr95314_global");
13
14 gcc_jit_rvalue *global_ref = gcc_jit_lvalue_get_address(global, NULL);
15
16 gcc_jit_param *param_string
17 = gcc_jit_context_new_param (ctxt, NULL, t_const_char_ptr, "string");
18 gcc_jit_function *puts_func
19 = gcc_jit_context_new_function (ctxt, NULL, GCC_JIT_FUNCTION_IMPORTED,
20 t_int, "puts", 1, &param_string, 0);
21
22 #define NUM_INNER_FNS 3
23 gcc_jit_function *inner_fns[NUM_INNER_FNS];
24 for (int i = 0; i < NUM_INNER_FNS; i++)
25 {
26 char fnname[128];
27 sprintf (fnname, "pr95314_inner_%i", i);
28 inner_fns[i]
29 = gcc_jit_context_new_function (ctxt, NULL, GCC_JIT_FUNCTION_INTERNAL,
30 t_void, fnname, 0, NULL, 0);
31 gcc_jit_block *block = gcc_jit_function_new_block (inner_fns[i], NULL);
32 gcc_jit_rvalue *arg
33 = gcc_jit_context_new_cast (ctxt, NULL, global_ref, t_const_char_ptr);
34 gcc_jit_block_add_eval (block, NULL,
35 gcc_jit_context_new_call (ctxt, NULL, puts_func,
36 1, &arg));
37 gcc_jit_block_end_with_void_return (block, NULL);
38 }
39
40 gcc_jit_function *outer_func
41 = gcc_jit_context_new_function (ctxt, NULL, GCC_JIT_FUNCTION_EXPORTED,
42 t_void, "pr95314_outer", 0, NULL, 0);
43 gcc_jit_block *block = gcc_jit_function_new_block (outer_func, NULL);
44 for (int i = 0; i < NUM_INNER_FNS; i++)
45 gcc_jit_block_add_eval (block, NULL,
46 gcc_jit_context_new_call (ctxt, NULL, inner_fns[i],
47 0, NULL));
48 gcc_jit_block_end_with_void_return (block, NULL);
49 }
50
51 void
52 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
53 {
54 CHECK_NON_NULL (result);
55 (void)gcc_jit_result_get_code (result, "pr95314_outer");
56 }