c++: prvalue of array type [PR111286]
[official-gcc.git] / gcc / testsuite / jit.dg / test-error-global-nonconst-init.c
blob9dffe06eac32a09428d1de5e2ebe3bea5e164484
1 /*
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()
8 */
10 #include <stdlib.h>
11 #include <stdio.h>
13 #include "libgccjit.h"
14 #include "harness.h"
16 void
17 create_code (gcc_jit_context *ctxt, void *user_data)
19 gcc_jit_type *int_type = gcc_jit_context_get_type (ctxt,
20 GCC_JIT_TYPE_INT);
22 gcc_jit_function *fn_int_3;
23 { /* int foo () { int local = 3; return local;} */
24 fn_int_3 =
25 gcc_jit_context_new_function (ctxt,
27 GCC_JIT_FUNCTION_EXPORTED,
28 int_type,
29 "fn_int_3",
32 0);
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,
36 int_type,
37 "local");
38 gcc_jit_rvalue *rval = gcc_jit_context_new_rvalue_from_int (
39 ctxt, int_type, 3);
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,
53 fn_int_3,
54 0,0);
56 gcc_jit_lvalue *foo = gcc_jit_context_new_global (
57 ctxt, NULL,
58 GCC_JIT_GLOBAL_EXPORTED,
59 int_type,
60 "global_nonconst_int");
61 gcc_jit_global_set_initializer_rvalue (foo,
62 rval);
66 void
67 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
69 /* Ensure that the bad API usage prevents the API giving a bogus
70 result back. */
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");