1 /*
2
3 Test that the proper error is triggered when we initialize
4 a global with a global that has no DECL_INITIAL (and is marked
5 DECL_COMMON(NODE) = 1).
6
7 */
8
9 #include <stdlib.h>
10 #include <stdio.h>
11
12 #include "libgccjit.h"
13 #include "harness.h"
14
15 void
16 create_code (gcc_jit_context *ctxt, void *user_data)
17 {
18 gcc_jit_type *int_type = gcc_jit_context_get_type (ctxt,
19 GCC_JIT_TYPE_INT);
20
21 /* const int foo;
22 int bar = foo;
23 */
24 gcc_jit_lvalue *foo = gcc_jit_context_new_global (
25 ctxt, NULL,
26 GCC_JIT_GLOBAL_EXPORTED,
27 gcc_jit_type_get_const (int_type),
28 "global_const_int_0");
29 gcc_jit_lvalue *bar = gcc_jit_context_new_global (
30 ctxt, NULL,
31 GCC_JIT_GLOBAL_EXPORTED,
32 int_type,
33 "global_lvalueinit_int_0");
34 gcc_jit_global_set_initializer_rvalue (bar,
35 gcc_jit_lvalue_as_rvalue (foo));
36 }
37
38 void
39 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
40 {
41 /* Ensure that the bad API usage prevents the API giving a bogus
42 result back. */
43 CHECK_VALUE (result, NULL);
44
45 /* Verify that the correct error message was emitted. */
46 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
47 "unable to convert initial value for the global "
48 "variable global_lvalueinit_int_0 to a compile-time"
49 " constant");
50 CHECK_STRING_VALUE (gcc_jit_context_get_last_error (ctxt),
51 "unable to convert initial value for the global "
52 "variable global_lvalueinit_int_0 to a compile-time"
53 " constant");
54 }