| 1 |
#include <libgccjit.h> |
| 2 |
|
| 3 |
#include "harness.h" |
| 4 |
|
| 5 |
/* Verify that we can compile a function that uses __builtin_unreachable |
| 6 |
(PR jit/95426). |
| 7 |
|
| 8 |
Compile the equivalent of this C: |
| 9 |
|
| 10 |
int test_pr95426_unreachable (int i) |
| 11 |
{ |
| 12 |
__builtin_unreachable (); |
| 13 |
return i; |
| 14 |
} |
| 15 |
*/ |
| 16 |
|
| 17 |
void |
| 18 |
create_code (gcc_jit_context *ctxt, void *user_data) |
| 19 |
{ |
| 20 |
gcc_jit_context_set_int_option (ctxt, |
| 21 |
GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL, |
| 22 |
0); |
| 23 |
|
| 24 |
gcc_jit_type *int_type = gcc_jit_context_get_type(ctxt, GCC_JIT_TYPE_INT); |
| 25 |
gcc_jit_param *param_i |
| 26 |
= gcc_jit_context_new_param (ctxt, NULL, int_type, "i"); |
| 27 |
gcc_jit_function *test_fn |
| 28 |
= gcc_jit_context_new_function (ctxt, NULL, GCC_JIT_FUNCTION_EXPORTED, |
| 29 |
int_type, |
| 30 |
"test_pr95426_unreachable", |
| 31 |
1, ¶m_i, 0); |
| 32 |
|
| 33 |
gcc_jit_block *bb = gcc_jit_function_new_block(test_fn, "start"); |
| 34 |
gcc_jit_function *func___builtin_unreachable |
| 35 |
= gcc_jit_context_get_builtin_function(ctxt, "__builtin_unreachable"); |
| 36 |
gcc_jit_rvalue *call___builtin_unreachable |
| 37 |
= gcc_jit_context_new_call(ctxt, NULL, func___builtin_unreachable, |
| 38 |
0, NULL); |
| 39 |
gcc_jit_block_add_eval(bb, NULL, call___builtin_unreachable); |
| 40 |
gcc_jit_block_end_with_return (bb, NULL, gcc_jit_param_as_rvalue(param_i)); |
| 41 |
} |
| 42 |
|
| 43 |
void |
| 44 |
verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) |
| 45 |
{ |
| 46 |
CHECK_NON_NULL (result); |
| 47 |
CHECK_NON_NULL (gcc_jit_result_get_code (result, "test_pr95426_unreachable")); |
| 48 |
/* Don't actually run the code. */ |
| 49 |
} |