| 1 |
#include <stdlib.h> |
| 2 |
#include <stdio.h> |
| 3 |
|
| 4 |
#include "libgccjit.h" |
| 5 |
|
| 6 |
#include "harness.h" |
| 7 |
|
| 8 |
void |
| 9 |
create_code (gcc_jit_context *ctxt, void *user_data) |
| 10 |
{ |
| 11 |
/* Let's try to inject the equivalent of: |
| 12 |
|
| 13 |
void |
| 14 |
test_fn () |
| 15 |
{ |
| 16 |
int i; |
| 17 |
i = "this is not an int"; |
| 18 |
} |
| 19 |
|
| 20 |
and verify that the API complains about the mismatching types |
| 21 |
in the assignment. |
| 22 |
*/ |
| 23 |
gcc_jit_type *void_type = |
| 24 |
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID); |
| 25 |
gcc_jit_type *int_type = |
| 26 |
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT); |
| 27 |
|
| 28 |
gcc_jit_function *test_fn = |
| 29 |
gcc_jit_context_new_function (ctxt, NULL, |
| 30 |
GCC_JIT_FUNCTION_EXPORTED, |
| 31 |
void_type, |
| 32 |
"test_fn", |
| 33 |
0, NULL, |
| 34 |
0); |
| 35 |
gcc_jit_lvalue *i = |
| 36 |
gcc_jit_function_new_local ( |
| 37 |
test_fn, NULL, int_type, "i"); |
| 38 |
|
| 39 |
gcc_jit_block *block = gcc_jit_function_new_block (test_fn, NULL); |
| 40 |
|
| 41 |
gcc_jit_block_add_assignment ( |
| 42 |
block, NULL, |
| 43 |
i, /* of type int */ |
| 44 |
gcc_jit_context_new_string_literal ( |
| 45 |
ctxt, "this is not an int")); |
| 46 |
gcc_jit_block_end_with_void_return (block, NULL); |
| 47 |
} |
| 48 |
|
| 49 |
void |
| 50 |
verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) |
| 51 |
{ |
| 52 |
CHECK_VALUE (result, NULL); |
| 53 |
|
| 54 |
/* Verify that the correct error message was emitted. */ |
| 55 |
CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt), |
| 56 |
"gcc_jit_block_add_assignment:" |
| 57 |
" mismatching types:" |
| 58 |
" assignment to i (type: int)" |
| 59 |
" from \"this is not an int\" (type: const char *)"); |
| 60 |
} |
| 61 |
|