1 /* Test of PR jit/66700. */
15 write_back_through_ptr (double *d
);
22 create_code (gcc_jit_context
*ctxt
, void *user_data
)
24 /* Let's try to inject the equivalent of:
27 test_caller_of_write_back_through_ptr (void)
31 write_back_through_ptr (&d);
35 gcc_jit_type
*t_void
=
36 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_VOID
);
37 gcc_jit_type
*t_double
=
38 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_DOUBLE
);
39 gcc_jit_type
*t_ptr_to_double
=
40 gcc_jit_type_get_pointer (t_double
);
42 /* Declare the imported function. */
43 gcc_jit_param
*params
[1];
45 gcc_jit_context_new_param (ctxt
, NULL
, t_ptr_to_double
, "d");
46 gcc_jit_function
*called_fn
=
47 gcc_jit_context_new_function (ctxt
, NULL
,
48 GCC_JIT_FUNCTION_IMPORTED
,
50 "write_back_through_ptr",
54 /* Build the test_fn. */
55 gcc_jit_function
*test_fn
=
56 gcc_jit_context_new_function (ctxt
, NULL
,
57 GCC_JIT_FUNCTION_EXPORTED
,
59 "test_caller_of_write_back_through_ptr",
63 gcc_jit_function_new_local (test_fn
, NULL
, t_double
, "d");
65 gcc_jit_block
*block
= gcc_jit_function_new_block (test_fn
, NULL
);
68 gcc_jit_block_add_assignment (
70 gcc_jit_context_new_rvalue_from_int (ctxt
, t_double
, 4));
72 /* "write_back_through_ptr (&d);" */
73 gcc_jit_rvalue
*args
[1];
74 args
[0] = gcc_jit_lvalue_get_address (d
, NULL
);
75 gcc_jit_block_add_eval (
77 gcc_jit_context_new_call (ctxt
,
81 gcc_jit_block_end_with_return (block
,
83 gcc_jit_lvalue_as_rvalue (d
));
87 write_back_through_ptr (double *d
)
93 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
95 typedef double (*fn_type
) (void);
96 CHECK_NON_NULL (result
);
98 fn_type test_caller_of_write_back_through_ptr
=
99 (fn_type
)gcc_jit_result_get_code (result
,
100 "test_caller_of_write_back_through_ptr");
101 CHECK_NON_NULL (test_caller_of_write_back_through_ptr
);
103 /* Call the JIT-generated function. */
104 double d
= test_caller_of_write_back_through_ptr ();
106 /* Verify that it correctly called "write_back_through_ptr". */
107 CHECK_VALUE (d
, 5.600000);