Debian Codegraph @

gcc/testsuite/jit.dg/test-error-ctor-union-wrong-field-name.c

raw
1 /*
2
3 Test that the proper error is triggered when we build a ctor
4 for an union type, but don't provide a correct 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 gcc_jit_type *double_type = gcc_jit_context_get_type (ctxt,
22 GCC_JIT_TYPE_DOUBLE);
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 float_type,
31 "b");
32 gcc_jit_field *b3 = gcc_jit_context_new_field (ctxt,
33 0,
34 double_type,
35 "c");
36 gcc_jit_field *fields_b[] = {b1, b2, b3};
37
38 gcc_jit_type *union_bar_type =
39 gcc_jit_context_new_union_type (ctxt,
40 0,
41 "bar",
42 3,
43 fields_b);
44
45 gcc_jit_field *b33 = gcc_jit_context_new_field (ctxt,
46 0,
47 double_type,
48 "c");
49
50 gcc_jit_rvalue *val =
51 gcc_jit_context_new_rvalue_from_double (ctxt, double_type, 1);
52
53 gcc_jit_rvalue *ctor = gcc_jit_context_new_union_constructor
54 (ctxt, 0,
55 union_bar_type,
56 b33,
57 val);
58
59 CHECK_VALUE (ctor, NULL);
60 }
61
62 void
63 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
64 {
65 /* Ensure that the bad API usage prevents the API giving a bogus
66 result back. */
67 CHECK_VALUE (result, NULL);
68
69 /* Verify that the correct error message was emitted. */
70 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
71 "gcc_jit_context_new_union_constructor: field object (c)"
72 " was not used when creating the type union bar");
73 CHECK_STRING_VALUE (gcc_jit_context_get_last_error (ctxt),
74 "gcc_jit_context_new_union_constructor: field object (c)"
75 " was not used when creating the type union bar");
76 }