| 1 |
#include <libgccjit.h> |
| 2 |
#include "harness.h" |
| 3 |
|
| 4 |
void |
| 5 |
create_code (gcc_jit_context *ctxt, void *user_data) |
| 6 |
{ |
| 7 |
/* Replay of API calls for ctxt. */ |
| 8 |
gcc_jit_type *type_long_long = |
| 9 |
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG_LONG); |
| 10 |
gcc_jit_type *type_void = |
| 11 |
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID); |
| 12 |
gcc_jit_type *type_void_ptr = |
| 13 |
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID_PTR); |
| 14 |
gcc_jit_field *field_u_signed = |
| 15 |
gcc_jit_context_new_field (ctxt, |
| 16 |
NULL, /* gcc_jit_location *loc */ |
| 17 |
type_long_long, /* gcc_jit_type *type, */ |
| 18 |
"u_signed"); /* const char *name */ |
| 19 |
gcc_jit_field *field_u_ptr = |
| 20 |
gcc_jit_context_new_field (ctxt, |
| 21 |
NULL, /* gcc_jit_location *loc */ |
| 22 |
type_void_ptr, /* gcc_jit_type *type, */ |
| 23 |
"u_ptr"); /* const char *name */ |
| 24 |
gcc_jit_field *fields_for_union_any[2] = { |
| 25 |
field_u_signed, |
| 26 |
field_u_ptr, |
| 27 |
}; |
| 28 |
gcc_jit_type *union_any = |
| 29 |
gcc_jit_context_new_union_type (ctxt, |
| 30 |
NULL, /* gcc_jit_location *loc */ |
| 31 |
"any", /* const char *name */ |
| 32 |
2, /* int num_fields */ |
| 33 |
fields_for_union_any); |
| 34 |
gcc_jit_function *func = |
| 35 |
gcc_jit_context_new_function (ctxt, /* gcc_jit_context *ctxt */ |
| 36 |
NULL, /* gcc_jit_location *loc */ |
| 37 |
GCC_JIT_FUNCTION_EXPORTED, |
| 38 |
type_void, /* gcc_jit_type *return_type */ |
| 39 |
"anonloop_0", /* const char *name */ |
| 40 |
0, /* int num_params */ |
| 41 |
NULL, /* gcc_jit_param **params */ |
| 42 |
0); /* int is_variadic */ |
| 43 |
gcc_jit_block *block_initial = |
| 44 |
gcc_jit_function_new_block (func, "initial"); |
| 45 |
|
| 46 |
gcc_jit_lvalue *local_tmp = |
| 47 |
gcc_jit_function_new_local (func, /* gcc_jit_function *func */ |
| 48 |
NULL, /* gcc_jit_location *loc */ |
| 49 |
union_any, /* gcc_jit_type *type */ |
| 50 |
"tmp"); /* const char *name */ |
| 51 |
|
| 52 |
/* "tmp.u_signed = 0x213d640;" */ |
| 53 |
gcc_jit_block_add_assignment ( |
| 54 |
block_initial, /*gcc_jit_block *block */ |
| 55 |
NULL, /* gcc_jit_location *loc */ |
| 56 |
gcc_jit_lvalue_access_field (local_tmp, /*gcc_jit_lvalue *struct_or_union */ |
| 57 |
NULL, /*gcc_jit_location *loc */ |
| 58 |
field_u_signed), |
| 59 |
gcc_jit_context_new_rvalue_from_long ( |
| 60 |
ctxt, /* gcc_jit_context *ctxt */ |
| 61 |
type_long_long, /* gcc_jit_type *numeric_type */ |
| 62 |
0x213d640)); /* long value */ |
| 63 |
|
| 64 |
/* "(*tmp.u_ptr) += 1;" which can't be done since u_ptr is a (void *). */ |
| 65 |
gcc_jit_block_add_assignment_op ( |
| 66 |
block_initial, /*gcc_jit_block *block */ |
| 67 |
NULL, /* gcc_jit_location *loc */ |
| 68 |
/* "(*tmp.u_ptr)". */ |
| 69 |
gcc_jit_rvalue_dereference ( |
| 70 |
gcc_jit_lvalue_as_rvalue ( |
| 71 |
gcc_jit_lvalue_access_field ( |
| 72 |
local_tmp, /*gcc_jit_lvalue *struct_or_union */ |
| 73 |
NULL, /*gcc_jit_location *loc */ |
| 74 |
field_u_ptr)), |
| 75 |
NULL), /* gcc_jit_location *loc */ |
| 76 |
GCC_JIT_BINARY_OP_PLUS, /* enum gcc_jit_binary_op op */ |
| 77 |
gcc_jit_context_new_rvalue_from_int ( |
| 78 |
ctxt, /* gcc_jit_context *ctxt */ |
| 79 |
type_long_long, /* gcc_jit_type *numeric_type */ |
| 80 |
1)); /* int value */ |
| 81 |
|
| 82 |
gcc_jit_block_end_with_void_return (block_initial, /*gcc_jit_block *block */ |
| 83 |
NULL); |
| 84 |
} |
| 85 |
|
| 86 |
void |
| 87 |
verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) |
| 88 |
{ |
| 89 |
CHECK_VALUE (result, NULL); |
| 90 |
|
| 91 |
/* Verify that the correct error message was emitted. */ |
| 92 |
CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt), |
| 93 |
"gcc_jit_rvalue_dereference:" |
| 94 |
" dereference of void pointer tmp.u_ptr" |
| 95 |
" (type: void *)"); |
| 96 |
} |