1 #include <stdlib.h>
2 #include <stdio.h>
3
4 #include "libgccjit.h"
5
6 #include "harness.h"
7
8 /* Try to declare a bit-field with invalid width. */
9
10 void
11 create_code (gcc_jit_context *ctxt, void *user_data)
12 {
13 gcc_jit_type *short_type =
14 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_SHORT);
15 gcc_jit_field *i =
16 gcc_jit_context_new_bitfield (ctxt,
17 NULL,
18 short_type,
19 3,
20 "i");
21 gcc_jit_field *j =
22 gcc_jit_context_new_bitfield (ctxt,
23 NULL,
24 short_type,
25 157,
26 "j");
27 gcc_jit_field *fields[] = {i, j};
28 gcc_jit_context_new_struct_type (ctxt, NULL, "bit_foo", 2, fields);
29 }
30
31 void
32 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
33 {
34 CHECK_VALUE (result, NULL);
35 char error_str[256];
36 snprintf (error_str, sizeof (error_str),
37 "width of bit-field j (width: 157) is wider than its type "
38 "(width: %zu)", 8 * sizeof (short));
39
40 /* Verify that the correct error message was emitted. */
41
42 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
43 error_str);
44 }