1 /*
2
3 Test that the proper error is triggered when we initialize
4 a global array with a ctor with too many values.
5
6 Using gcc_jit_global_set_initializer_rvalue()
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 { /* float foo[1] = {1,2}; */
19
20 gcc_jit_type *float_type = gcc_jit_context_get_type (ctxt,
21 GCC_JIT_TYPE_FLOAT);
22 gcc_jit_type *arr_type = gcc_jit_context_new_array_type (ctxt,
23 0,
24 float_type,
25 1);
26 gcc_jit_rvalue *rval_1 = gcc_jit_context_new_rvalue_from_int (
27 ctxt, float_type, 1);
28 gcc_jit_rvalue *rval_2 = gcc_jit_context_new_rvalue_from_int (
29 ctxt, float_type, 2);
30
31 gcc_jit_rvalue *values[] = {rval_1, rval_2};
32
33 gcc_jit_rvalue *ctor = gcc_jit_context_new_array_constructor (ctxt,
34 0,
35 arr_type,
36 2,
37 values);
38 if (!ctor)
39 return;
40
41 gcc_jit_lvalue *foo = gcc_jit_context_new_global (
42 ctxt, NULL,
43 GCC_JIT_GLOBAL_EXPORTED,
44 arr_type,
45 "global_floatarr_12");
46 gcc_jit_global_set_initializer_rvalue (foo, ctor);
47 }
48
49 void
50 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
51 {
52 /* Ensure that the bad API usage prevents the API giving a bogus
53 result back. */
54 CHECK_VALUE (result, NULL);
55
56 /* Verify that the correct error message was emitted. */
57 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
58 "gcc_jit_context_new_array_constructor: array "
59 "constructor has more values than the array type's "
60 "length (array type length: 1, constructor length: 2)");
61 CHECK_STRING_VALUE (gcc_jit_context_get_last_error (ctxt),
62 "gcc_jit_context_new_array_constructor: array "
63 "constructor has more values than the array type's "
64 "length (array type length: 1, constructor length: 2)");
65 }