Debian Codegraph @

gcc/testsuite/jit.dg/test-pr117886-write-reproducer.c

raw
1 /* Verify that we can generate and compile reproducers for
2 gcc_jit_context_new_array_constructor
3 when the values are lvalues */
4
5 #include <stdio.h>
6 #include <string.h>
7
8 #include "libgccjit.h"
9 #include "harness.h"
10
11 /*
12 int foo[3];
13
14 void test (void)
15 {
16 int a = 1;
17 int b = 2;
18 int c = 3;
19 foo = {a,b,c};
20 }
21 */
22
23 void
24 create_code (gcc_jit_context *ctxt, void *user_data)
25 {
26 gcc_jit_type *int_type
27 = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
28 gcc_jit_type *void_type
29 = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
30
31 gcc_jit_type *arr_type = gcc_jit_context_new_array_type (ctxt,
32 0,
33 int_type,
34 3);
35 gcc_jit_lvalue *global_intarr_123 = gcc_jit_context_new_global (
36 ctxt, NULL,
37 GCC_JIT_GLOBAL_EXPORTED,
38 arr_type,
39 "global_intarr_123");
40
41 gcc_jit_function *func =
42 gcc_jit_context_new_function (ctxt, NULL,
43 GCC_JIT_FUNCTION_EXPORTED,
44 void_type,
45 "initialize_intarr_123",
46 0, NULL, 0);
47 gcc_jit_lvalue *a
48 = gcc_jit_function_new_local (func, NULL, int_type, "a");
49 gcc_jit_lvalue *b
50 = gcc_jit_function_new_local (func, NULL, int_type, "b");
51 gcc_jit_lvalue *c
52 = gcc_jit_function_new_local (func, NULL, int_type, "c");
53
54 gcc_jit_block *bb =
55 gcc_jit_function_new_block (func, "initial");
56
57 gcc_jit_block_add_assignment (bb, NULL,
58 a, gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 1));
59 gcc_jit_block_add_assignment (bb, NULL,
60 b, gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 2));
61 gcc_jit_block_add_assignment (bb, NULL,
62 c, gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 3));
63
64 gcc_jit_rvalue *values[] = {(gcc_jit_rvalue *)a,
65 (gcc_jit_rvalue *)b,
66 (gcc_jit_rvalue *)c};
67 gcc_jit_rvalue *ctor = gcc_jit_context_new_array_constructor (ctxt,
68 0,
69 arr_type,
70 3,
71 values);
72 gcc_jit_block_add_assignment (bb, NULL,
73 global_intarr_123,
74 ctor);
75
76 gcc_jit_block_end_with_void_return (bb, NULL);
77 }
78
79 void
80 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
81 {
82 CHECK_NON_NULL (result);
83
84 typedef void (*my_fn_type) (void);
85 my_fn_type initialize_intarr_123
86 = (my_fn_type)gcc_jit_result_get_code (result, "initialize_intarr_123");
87 CHECK_NON_NULL (initialize_intarr_123);
88
89 {
90 int *foo = gcc_jit_result_get_global (result, "global_intarr_123");
91 CHECK_NON_NULL (foo);
92
93 CHECK_VALUE (foo[0], 0);
94 CHECK_VALUE (foo[1], 0);
95 CHECK_VALUE (foo[2], 0);
96
97 initialize_intarr_123 ();
98
99 CHECK_VALUE (foo[0], 1);
100 CHECK_VALUE (foo[1], 2);
101 CHECK_VALUE (foo[2], 3);
102 }
103 }