Debian Codegraph @

gcc/testsuite/jit.dg/test-error-ctor-struct-wrong-type.c

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