| 1 |
/* |
| 2 |
|
| 3 |
Test that the proper error is triggered when we build a ctor |
| 4 |
for an struct type, but has the type wrong on a field. |
| 5 |
|
| 6 |
Like test-error-ctor-struct-wrong-type.c, but with implicit fields. |
| 7 |
|
| 8 |
*/ |
| 9 |
|
| 10 |
#include <stdlib.h> |
| 11 |
#include <stdio.h> |
| 12 |
|
| 13 |
#include "libgccjit.h" |
| 14 |
#include "harness.h" |
| 15 |
|
| 16 |
void |
| 17 |
create_code (gcc_jit_context *ctxt, void *user_data) |
| 18 |
{ |
| 19 |
gcc_jit_type *int_type = gcc_jit_context_get_type (ctxt, |
| 20 |
GCC_JIT_TYPE_INT); |
| 21 |
gcc_jit_type *float_type = gcc_jit_context_get_type (ctxt, |
| 22 |
GCC_JIT_TYPE_FLOAT); |
| 23 |
|
| 24 |
gcc_jit_field *b1 = gcc_jit_context_new_field (ctxt, |
| 25 |
0, |
| 26 |
int_type, |
| 27 |
"a"); |
| 28 |
gcc_jit_field *b2 = gcc_jit_context_new_field (ctxt, |
| 29 |
0, |
| 30 |
int_type, |
| 31 |
"b"); |
| 32 |
gcc_jit_field *b3 = gcc_jit_context_new_field (ctxt, |
| 33 |
0, |
| 34 |
int_type, |
| 35 |
"c"); |
| 36 |
gcc_jit_field *fields_b[] = {b1, b2, b3}; |
| 37 |
|
| 38 |
gcc_jit_type *struct_bar_type = |
| 39 |
gcc_jit_struct_as_type ( |
| 40 |
gcc_jit_context_new_struct_type (ctxt, |
| 41 |
0, |
| 42 |
"bar", |
| 43 |
3, |
| 44 |
fields_b)); |
| 45 |
gcc_jit_rvalue *frv = gcc_jit_context_new_rvalue_from_double (ctxt, |
| 46 |
float_type, |
| 47 |
12); |
| 48 |
|
| 49 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_struct_constructor |
| 50 |
(ctxt, 0, |
| 51 |
struct_bar_type, |
| 52 |
1, |
| 53 |
0, |
| 54 |
&frv); |
| 55 |
|
| 56 |
CHECK_VALUE (ctor, NULL); |
| 57 |
} |
| 58 |
|
| 59 |
void |
| 60 |
verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) |
| 61 |
{ |
| 62 |
/* Ensure that the bad API usage prevents the API giving a bogus |
| 63 |
result back. */ |
| 64 |
CHECK_VALUE (result, NULL); |
| 65 |
|
| 66 |
/* Verify that the correct error message was emitted. */ |
| 67 |
CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt), |
| 68 |
"gcc_jit_context_new_struct_constructor: value and " |
| 69 |
"field not " |
| 70 |
"the same unqualified type, " |
| 71 |
"at index 0 (struct bar.a: int)(value type: float)"); |
| 72 |
CHECK_STRING_VALUE (gcc_jit_context_get_last_error (ctxt), |
| 73 |
"gcc_jit_context_new_struct_constructor: value and " |
| 74 |
"field not " |
| 75 |
"the same unqualified type, " |
| 76 |
"at index 0 (struct bar.a: int)(value type: float)"); |
| 77 |
} |