Preserve SSA info for more propagated copy
[official-gcc.git] / gcc / testsuite / jit.dg / test-error-ctor-union-wrong-field-name.c
blob2bf8ee4023e0c94bce76a8ec8eb766bf06eb4d46
1 /*
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.
6 */
8 #include <stdlib.h>
9 #include <stdio.h>
11 #include "libgccjit.h"
12 #include "harness.h"
14 void
15 create_code (gcc_jit_context *ctxt, void *user_data)
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);
24 gcc_jit_field *b1 = gcc_jit_context_new_field (ctxt,
26 int_type,
27 "a");
28 gcc_jit_field *b2 = gcc_jit_context_new_field (ctxt,
30 float_type,
31 "b");
32 gcc_jit_field *b3 = gcc_jit_context_new_field (ctxt,
34 double_type,
35 "c");
36 gcc_jit_field *fields_b[] = {b1, b2, b3};
38 gcc_jit_type *union_bar_type =
39 gcc_jit_context_new_union_type (ctxt,
41 "bar",
43 fields_b);
45 gcc_jit_field *b33 = gcc_jit_context_new_field (ctxt,
47 double_type,
48 "c");
50 gcc_jit_rvalue *val =
51 gcc_jit_context_new_rvalue_from_double (ctxt, double_type, 1);
53 gcc_jit_rvalue *ctor = gcc_jit_context_new_union_constructor
54 (ctxt, 0,
55 union_bar_type,
56 b33,
57 val);
59 CHECK_VALUE (ctor, NULL);
62 void
63 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
65 /* Ensure that the bad API usage prevents the API giving a bogus
66 result back. */
67 CHECK_VALUE (result, NULL);
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");