12 struct box
{ char dummy
[64]; int i
; };
15 returns_struct (int i
);
22 create_code (gcc_jit_context
*ctxt
, void *user_data
)
24 /* Let's try to inject the equivalent of:
28 return [MUST TAIL CALL] returns_struct (i).i;
31 and verify that we get a sane error when the tail call
32 optimization can't be done. */
34 gcc_jit_type
*char_type
=
35 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_CHAR
);
36 gcc_jit_type
*int_type
=
37 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_INT
);
39 /* Declare "struct box. */
40 gcc_jit_type
*array_type
=
41 gcc_jit_context_new_array_type (ctxt
, NULL
, char_type
, 64);
42 gcc_jit_field
*field_dummy
=
43 gcc_jit_context_new_field (ctxt
, NULL
, array_type
, "dummy");
44 gcc_jit_field
*field_i
=
45 gcc_jit_context_new_field (ctxt
, NULL
, int_type
, "i");
46 gcc_jit_field
*fields
[2] = {field_dummy
, field_i
};
47 gcc_jit_struct
*struct_box
=
48 gcc_jit_context_new_struct_type (ctxt
, NULL
, "box", 2, fields
);
50 /* Declare the imported function. */
51 gcc_jit_param
*called_fn_param_i
=
52 gcc_jit_context_new_param (ctxt
, NULL
, int_type
, "i");
53 gcc_jit_function
*called_fn
=
54 gcc_jit_context_new_function (ctxt
, NULL
,
55 GCC_JIT_FUNCTION_IMPORTED
,
56 gcc_jit_struct_as_type (struct_box
),
58 1, &called_fn_param_i
,
61 /* Build the test_fn. */
62 gcc_jit_param
*caller_param_i
=
63 gcc_jit_context_new_param (ctxt
, NULL
, int_type
, "i");
64 gcc_jit_function
*test_fn
=
65 gcc_jit_context_new_function (ctxt
, NULL
,
66 GCC_JIT_FUNCTION_EXPORTED
,
71 gcc_jit_rvalue
*arg
= gcc_jit_param_as_rvalue (caller_param_i
);
73 gcc_jit_rvalue
*call
=
74 gcc_jit_context_new_call (ctxt
, NULL
,
78 /* Mark the call as requiring tail-call optimization. */
79 gcc_jit_rvalue_set_bool_require_tail_call (call
, 1);
81 gcc_jit_block
*block
= gcc_jit_function_new_block (test_fn
, NULL
);
82 gcc_jit_block_end_with_return (block
, NULL
,
83 gcc_jit_rvalue_access_field (call
, NULL
, field_i
));
87 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
89 CHECK_VALUE (result
, NULL
);
91 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt
),
92 "cannot tail-call: callee returns a structure");