| 1 |
/* |
| 2 |
|
| 3 |
Test that the proper error is triggered when we build a ctor |
| 4 |
for an struct type, but try to use a field object that was not |
| 5 |
used to create the struct type. |
| 6 |
|
| 7 |
*/ |
| 8 |
|
| 9 |
#include <stdlib.h> |
| 10 |
#include <stdio.h> |
| 11 |
|
| 12 |
#include "libgccjit.h" |
| 13 |
#include "harness.h" |
| 14 |
|
| 15 |
void |
| 16 |
create_code (gcc_jit_context *ctxt, void *user_data) |
| 17 |
{ |
| 18 |
gcc_jit_type *int_type = gcc_jit_context_get_type (ctxt, |
| 19 |
GCC_JIT_TYPE_INT); |
| 20 |
|
| 21 |
gcc_jit_field *b1 = gcc_jit_context_new_field (ctxt, |
| 22 |
0, |
| 23 |
int_type, |
| 24 |
"a"); |
| 25 |
gcc_jit_field *b2 = gcc_jit_context_new_field (ctxt, |
| 26 |
0, |
| 27 |
int_type, |
| 28 |
"b"); |
| 29 |
gcc_jit_field *b3 = gcc_jit_context_new_field (ctxt, |
| 30 |
0, |
| 31 |
int_type, |
| 32 |
"c"); |
| 33 |
gcc_jit_field *b4 = gcc_jit_context_new_field (ctxt, |
| 34 |
0, |
| 35 |
int_type, |
| 36 |
"d"); |
| 37 |
gcc_jit_field *b5 = gcc_jit_context_new_field (ctxt, |
| 38 |
0, |
| 39 |
int_type, |
| 40 |
"d"); |
| 41 |
gcc_jit_field *fields_b[] = {b1, b2, b3, b4, b5}; |
| 42 |
|
| 43 |
gcc_jit_type *struct_bar_type = |
| 44 |
gcc_jit_struct_as_type ( |
| 45 |
gcc_jit_context_new_struct_type (ctxt, |
| 46 |
0, |
| 47 |
"bar", |
| 48 |
5, |
| 49 |
fields_b)); |
| 50 |
|
| 51 |
|
| 52 |
gcc_jit_field *b44 = gcc_jit_context_new_field (ctxt, |
| 53 |
0, |
| 54 |
int_type, |
| 55 |
"c"); |
| 56 |
|
| 57 |
gcc_jit_field *fields_ctor[] = {b1, b2, b44, b5}; |
| 58 |
gcc_jit_rvalue *values[] = {0,0,0,0}; |
| 59 |
|
| 60 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_struct_constructor |
| 61 |
(ctxt, 0, |
| 62 |
struct_bar_type, |
| 63 |
4, |
| 64 |
fields_ctor, |
| 65 |
values); |
| 66 |
|
| 67 |
CHECK_VALUE (ctor, NULL); |
| 68 |
} |
| 69 |
|
| 70 |
void |
| 71 |
verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) |
| 72 |
{ |
| 73 |
/* Ensure that the bad API usage prevents the API giving a bogus |
| 74 |
result back. */ |
| 75 |
CHECK_VALUE (result, NULL); |
| 76 |
|
| 77 |
/* Verify that the correct error message was emitted. */ |
| 78 |
CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt), |
| 79 |
"gcc_jit_context_new_struct_constructor: field object " |
| 80 |
"at index 2 (c), was not used when creating the " |
| 81 |
"struct bar"); |
| 82 |
CHECK_STRING_VALUE (gcc_jit_context_get_last_error (ctxt), |
| 83 |
"gcc_jit_context_new_struct_constructor: field object " |
| 84 |
"at index 2 (c), was not used when creating the " |
| 85 |
"struct bar"); |
| 86 |
} |