| 1 |
#include <stdlib.h> |
| 2 |
#include <stdio.h> |
| 3 |
#include <stddef.h> |
| 4 |
|
| 5 |
#include "libgccjit.h" |
| 6 |
|
| 7 |
#include "harness.h" |
| 8 |
|
| 9 |
void |
| 10 |
create_code (gcc_jit_context *ctxt, void *user_data) |
| 11 |
{ |
| 12 |
/* Let's try to inject the equivalent of: |
| 13 |
int test_signed_char () |
| 14 |
{ |
| 15 |
char val = -2; |
| 16 |
return (int) val; |
| 17 |
} |
| 18 |
*/ |
| 19 |
gcc_jit_type *char_type = |
| 20 |
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_CHAR); |
| 21 |
gcc_jit_type *int_type = |
| 22 |
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT); |
| 23 |
|
| 24 |
gcc_jit_function *test_fn = |
| 25 |
gcc_jit_context_new_function (ctxt, NULL, |
| 26 |
GCC_JIT_FUNCTION_EXPORTED, |
| 27 |
int_type, |
| 28 |
"test_signed_char", |
| 29 |
0, NULL, |
| 30 |
0); |
| 31 |
|
| 32 |
gcc_jit_block *block = gcc_jit_function_new_block(test_fn, "entry"); |
| 33 |
|
| 34 |
gcc_jit_rvalue *val = gcc_jit_context_new_rvalue_from_int (ctxt, |
| 35 |
char_type, -2); |
| 36 |
gcc_jit_rvalue *return_value = gcc_jit_context_new_cast ( |
| 37 |
ctxt, NULL, val, int_type); |
| 38 |
|
| 39 |
gcc_jit_block_end_with_return (block, NULL, return_value); |
| 40 |
} |
| 41 |
|
| 42 |
void |
| 43 |
verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) |
| 44 |
{ |
| 45 |
CHECK_NON_NULL (result); |
| 46 |
|
| 47 |
typedef int (*fn_type) (); |
| 48 |
fn_type test_signed_char = |
| 49 |
(fn_type)gcc_jit_result_get_code (result, "test_signed_char"); |
| 50 |
CHECK_NON_NULL (test_signed_char); |
| 51 |
CHECK_VALUE (test_signed_char (), -2); |
| 52 |
} |