8 /* Reproducer for PR jit/66779.
10 Inject the equivalent of:
11 T FUNCNAME (T i, T j, T k)
13 bool comp0 = i & 0x40;
14 bool comp1 = (j == k);
20 for some type T; this was segfaulting during the expansion to RTL
21 due to missing handling for some machine modes in
22 jit_langhook_type_for_mode. */
25 create_fn (gcc_jit_context
*ctxt
,
27 enum gcc_jit_types jit_type
)
29 gcc_jit_type
*the_type
=
30 gcc_jit_context_get_type (ctxt
, jit_type
);
31 gcc_jit_type
*t_bool
=
32 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_BOOL
);
33 gcc_jit_param
*param_i
=
34 gcc_jit_context_new_param (ctxt
, NULL
, the_type
, "i");
35 gcc_jit_param
*param_j
=
36 gcc_jit_context_new_param (ctxt
, NULL
, the_type
, "j");
37 gcc_jit_param
*param_k
=
38 gcc_jit_context_new_param (ctxt
, NULL
, the_type
, "k");
39 gcc_jit_param
*params
[3] = {
44 gcc_jit_function
*func
=
45 gcc_jit_context_new_function (ctxt
, NULL
,
46 GCC_JIT_FUNCTION_EXPORTED
,
51 gcc_jit_block
*b_entry
= gcc_jit_function_new_block (func
, "entry");
52 gcc_jit_block
*b_on_true
= gcc_jit_function_new_block (func
, "on_true");
53 gcc_jit_block
*b_on_false
= gcc_jit_function_new_block (func
, "on_false");
55 gcc_jit_lvalue
*comp0
=
56 gcc_jit_function_new_local (func
, NULL
, t_bool
, "comp0");
58 gcc_jit_block_add_assignment (
61 gcc_jit_context_new_comparison (
63 GCC_JIT_COMPARISON_NE
,
64 gcc_jit_context_new_binary_op (
66 GCC_JIT_BINARY_OP_BITWISE_AND
,
68 gcc_jit_param_as_rvalue (param_i
),
69 gcc_jit_context_new_rvalue_from_int (ctxt
, the_type
, 0x40)),
70 gcc_jit_context_zero (ctxt
, the_type
)));
72 gcc_jit_lvalue
*comp1
=
73 gcc_jit_function_new_local (func
, NULL
, t_bool
, "comp1");
75 gcc_jit_block_add_assignment (
78 gcc_jit_context_new_comparison (ctxt
, NULL
,
79 GCC_JIT_COMPARISON_EQ
,
80 gcc_jit_param_as_rvalue (param_j
),
81 gcc_jit_param_as_rvalue (param_k
)));
83 gcc_jit_rvalue
*cond
=
84 gcc_jit_context_new_binary_op (ctxt
, NULL
,
85 GCC_JIT_BINARY_OP_LOGICAL_AND
,
87 gcc_jit_lvalue_as_rvalue (comp0
),
88 gcc_jit_lvalue_as_rvalue (comp1
));
90 gcc_jit_block_end_with_conditional (b_entry
, NULL
,
95 gcc_jit_block_end_with_return (
97 gcc_jit_context_new_rvalue_from_int (ctxt
, the_type
, 7));
99 gcc_jit_block_end_with_return (
101 gcc_jit_context_new_rvalue_from_int (ctxt
, the_type
, 22));
105 create_code (gcc_jit_context
*ctxt
, void *user_data
)
107 create_fn (ctxt
, "pr66779_signed_char", GCC_JIT_TYPE_SIGNED_CHAR
);
108 create_fn (ctxt
, "pr66779_unsigned_char", GCC_JIT_TYPE_UNSIGNED_CHAR
);
110 create_fn (ctxt
, "pr66779_short", GCC_JIT_TYPE_SHORT
);
111 create_fn (ctxt
, "pr66779_unsigned_short", GCC_JIT_TYPE_UNSIGNED_SHORT
);
113 create_fn (ctxt
, "pr66779_int", GCC_JIT_TYPE_INT
);
114 create_fn (ctxt
, "pr66779_unsigned_int", GCC_JIT_TYPE_UNSIGNED_INT
);
116 create_fn (ctxt
, "pr66779_long", GCC_JIT_TYPE_LONG
);
117 create_fn (ctxt
, "pr66779_unsigned_long", GCC_JIT_TYPE_UNSIGNED_LONG
);
119 create_fn (ctxt
, "pr66779_long_long",
120 GCC_JIT_TYPE_LONG_LONG
);
121 create_fn (ctxt
, "pr66779_unsigned_long_long",
122 GCC_JIT_TYPE_UNSIGNED_LONG_LONG
);
124 create_fn (ctxt
, "pr66779_size_t", GCC_JIT_TYPE_SIZE_T
);
128 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
130 typedef int (*fn_type
) (int, int, int);
131 CHECK_NON_NULL (result
);
132 /* Sanity-check the "int" case. */
134 (fn_type
)gcc_jit_result_get_code (result
, "pr66779_int");
136 CHECK_VALUE (fn (0, 0, 0), 22);
137 CHECK_VALUE (fn (0, 0, 1), 22);
138 CHECK_VALUE (fn (0x40, 0, 0), 7);
139 CHECK_VALUE (fn (0x40, 0, 1), 22);
140 CHECK_VALUE (fn (0x40, 1, 1), 7);
141 CHECK_VALUE (fn (0x3f, 0, 0), 22);
142 CHECK_VALUE (fn (0x3f, 1, 1), 22);