3 Test that the proper error is triggered when we initialize
4 a global with a function call.
6 Using gcc_jit_global_set_initializer_rvalue()
13 #include "libgccjit.h"
17 create_code (gcc_jit_context
*ctxt
, void *user_data
)
19 gcc_jit_type
*int_type
= gcc_jit_context_get_type (ctxt
,
22 gcc_jit_function
*fn_int_3
;
23 { /* int foo () { int local = 3; return local;} */
25 gcc_jit_context_new_function (ctxt
,
27 GCC_JIT_FUNCTION_EXPORTED
,
33 gcc_jit_block
*block
= gcc_jit_function_new_block (fn_int_3
, "start");
34 gcc_jit_lvalue
*local
= gcc_jit_function_new_local (fn_int_3
,
38 gcc_jit_rvalue
*rval
= gcc_jit_context_new_rvalue_from_int (
41 gcc_jit_block_add_assignment (block
, 0, local
, rval
);
43 gcc_jit_block_end_with_return (block
,
45 gcc_jit_lvalue_as_rvalue(local
));
49 { /* int bar = foo(); */
50 gcc_jit_rvalue
*rval
=
51 gcc_jit_context_new_call (ctxt
,
56 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
58 GCC_JIT_GLOBAL_EXPORTED
,
60 "global_nonconst_int");
61 gcc_jit_global_set_initializer_rvalue (foo
,
67 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
69 /* Ensure that the bad API usage prevents the API giving a bogus
71 CHECK_VALUE (result
, NULL
);
73 /* Verify that the correct error message was emitted. */
74 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt
),
75 "unable to convert initial value for the global variable"
76 " global_nonconst_int to a compile-time constant");
77 CHECK_STRING_VALUE (gcc_jit_context_get_last_error (ctxt
),
78 "unable to convert initial value for the global variable"
79 " global_nonconst_int to a compile-time constant");