OpenMP/C++: Use STRIP_REFERENCE_REF to fix declare variant with reference-returning...
[official-gcc.git] / gcc / testsuite / jit.dg / test-bitcast.c
blob2f80045293fc731883e1474e64749a1ffb54dc73
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdint.h>
6 #include "libgccjit.h"
8 #include "harness.h"
10 void
11 create_code (gcc_jit_context *ctxt, void *user_data)
13 /* Let's try to inject the equivalent of:
14 int32_t
15 my_bitcast (float x)
17 return bitcast(x, int32_t);
20 gcc_jit_type *int32 =
21 gcc_jit_context_get_int_type (ctxt, 4, 1);
22 gcc_jit_type *float_type =
23 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FLOAT);
25 gcc_jit_param *x =
26 gcc_jit_context_new_param (
27 ctxt,
28 NULL,
29 float_type, "x");
30 gcc_jit_param *params[1] = {x};
31 gcc_jit_function *func =
32 gcc_jit_context_new_function (ctxt,
33 NULL,
34 GCC_JIT_FUNCTION_EXPORTED,
35 int32,
36 "my_bitcast",
37 1, params, 0);
39 gcc_jit_block *initial =
40 gcc_jit_function_new_block (func, "initial");
42 gcc_jit_block_end_with_return(initial, NULL,
43 gcc_jit_context_new_bitcast(ctxt,
44 NULL,
45 gcc_jit_param_as_rvalue(x),
46 int32
47 ));
50 void
51 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
53 typedef int32_t (*my_bitcast_fn_type) (float);
54 CHECK_NON_NULL (result);
55 my_bitcast_fn_type my_bitcast =
56 (my_bitcast_fn_type)gcc_jit_result_get_code (result, "my_bitcast");
57 CHECK_NON_NULL (my_bitcast);
58 int32_t val = my_bitcast (3.1415927f);
59 note ("my_bitcast returned: 0x%x", val);
60 CHECK_VALUE (val, 0x40490FDB);