1 /* This testcase checks that gcc_jit_global_set_initializer_rvalue() works
2 with rvalues, especially with gcc_jit_context_new_*_constructor() for
3 struct, unions and arrays. */
12 create_code (gcc_jit_context
*ctxt
, void *user_data
)
14 gcc_jit_type
*int_type
= gcc_jit_context_get_type (ctxt
,
16 gcc_jit_type
*short_type
= gcc_jit_context_get_type (ctxt
,
18 gcc_jit_type
*pint_type
= gcc_jit_type_get_pointer (int_type
);
19 gcc_jit_type
*double_type
= gcc_jit_context_get_type (ctxt
,
21 gcc_jit_type
*float_type
= gcc_jit_context_get_type (ctxt
,
23 gcc_jit_type
*bool_type
= gcc_jit_context_get_type (ctxt
,
25 gcc_jit_type
*char_type
= gcc_jit_context_get_type (ctxt
,
27 gcc_jit_type
*cpchar_type
= gcc_jit_context_get_type (ctxt
,
28 GCC_JIT_TYPE_CONST_CHAR_PTR
);
29 gcc_jit_type
*size_type
= gcc_jit_context_get_type (ctxt
,
32 /* Make a struct: struct fi { float f; int i;} */
33 gcc_jit_field
*fi_f
= gcc_jit_context_new_field (ctxt
,
37 gcc_jit_field
*fi_i
= gcc_jit_context_new_field (ctxt
,
41 gcc_jit_field
*fields
[] = {fi_f
, fi_i
};
43 gcc_jit_type
*struct_fi_type
=
44 gcc_jit_struct_as_type (
45 gcc_jit_context_new_struct_type (ctxt
,
59 gcc_jit_field
*bar_ff
= gcc_jit_context_new_field (ctxt
,
63 gcc_jit_field
*bar_ii
= gcc_jit_context_new_field (ctxt
,
67 gcc_jit_field
*bar_fi
= gcc_jit_context_new_field (ctxt
,
71 gcc_jit_field
*fields2
[] = {bar_ff
, bar_fi
, bar_ii
};
73 gcc_jit_type
*struct_bar_type
=
74 gcc_jit_struct_as_type (
75 gcc_jit_context_new_struct_type (ctxt
,
88 gcc_jit_field
*ubar_ff
= gcc_jit_context_new_field (ctxt
,
92 gcc_jit_field
*ubar_ii
= gcc_jit_context_new_field (ctxt
,
96 gcc_jit_field
*fields3
[] = {ubar_ff
, ubar_ii
};
98 gcc_jit_type
*ubar
= gcc_jit_context_new_union_type (ctxt
,
104 { /* struct bar bar = {.ff=1, .fi={.f=2, .i=3}, .ii=4};
105 I.e. nested ctors and with fields specified
107 gcc_jit_lvalue
*bar
= gcc_jit_context_new_global (
109 GCC_JIT_GLOBAL_EXPORTED
,
111 "global_struct_bar_1234_1");
113 gcc_jit_rvalue
*fval
= gcc_jit_context_new_rvalue_from_int (
114 ctxt
, float_type
, 2);
115 gcc_jit_rvalue
*ival
= gcc_jit_context_new_rvalue_from_int (
118 gcc_jit_rvalue
*vals
[] = { fval
, ival
};
119 gcc_jit_field
*fields
[] = {fi_f
, fi_i
};
121 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_struct_constructor
128 ival
= gcc_jit_context_new_rvalue_from_int (
130 fval
= gcc_jit_context_new_rvalue_from_int (
131 ctxt
, float_type
, 1);
133 gcc_jit_rvalue
*vals2
[] = {fval
, ctor
, ival
};
134 gcc_jit_field
*fields2
[] = {bar_ff
, bar_fi
, bar_ii
};
136 gcc_jit_rvalue
*ctor_bar
= gcc_jit_context_new_struct_constructor
143 gcc_jit_global_set_initializer_rvalue (bar
, ctor_bar
);
145 { /* struct bar bar = {1, {2, 3}, 4};
146 I.e. nested ctors and fields implicit in definition order (fields=NULL)
148 gcc_jit_lvalue
*bar
= gcc_jit_context_new_global (
150 GCC_JIT_GLOBAL_EXPORTED
,
152 "global_struct_bar_1234_2");
154 gcc_jit_rvalue
*fval
= gcc_jit_context_new_rvalue_from_int (
155 ctxt
, float_type
, 2);
156 gcc_jit_rvalue
*ival
= gcc_jit_context_new_rvalue_from_int (
159 gcc_jit_rvalue
*vals
[] = { fval
, ival
};
161 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_struct_constructor
168 ival
= gcc_jit_context_new_rvalue_from_int (
170 fval
= gcc_jit_context_new_rvalue_from_int (
171 ctxt
, float_type
, 1);
173 gcc_jit_rvalue
*vals2
[] = {fval
, ctor
, ival
};
175 gcc_jit_rvalue
*ctor_bar
= gcc_jit_context_new_struct_constructor
182 gcc_jit_global_set_initializer_rvalue (bar
, ctor_bar
);
184 { /* struct fi foo = {.f=2, .i=3}; */
185 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
187 GCC_JIT_GLOBAL_EXPORTED
,
189 "global_struct_fi_23_1");
191 gcc_jit_rvalue
*fval
= gcc_jit_context_new_rvalue_from_int (
192 ctxt
, float_type
, 2);
193 gcc_jit_rvalue
*ival
= gcc_jit_context_new_rvalue_from_int (
196 gcc_jit_rvalue
*vals
[] = { fval
, ival
};
197 gcc_jit_field
*fields
[] = {fi_f
, fi_i
};
199 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_struct_constructor
206 gcc_jit_global_set_initializer_rvalue (foo
, ctor
);
208 { /* struct fi foo = {2, 3}; */
209 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
211 GCC_JIT_GLOBAL_EXPORTED
,
213 "global_struct_fi_23_2");
215 gcc_jit_rvalue
*fval
= gcc_jit_context_new_rvalue_from_int (
216 ctxt
, float_type
, 2);
217 gcc_jit_rvalue
*ival
= gcc_jit_context_new_rvalue_from_int (
220 gcc_jit_rvalue
*vals
[] = { fval
, ival
};
222 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_struct_constructor
229 gcc_jit_global_set_initializer_rvalue (foo
, ctor
);
231 { /* struct fi foo = {.i=0, .f=0}; (null init) */
232 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
234 GCC_JIT_GLOBAL_EXPORTED
,
236 "global_struct_fi_00_1");
238 gcc_jit_rvalue
*vals
[] = { 0, 0};
239 gcc_jit_field
*fields
[] = {fi_f
, fi_i
};
241 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_struct_constructor
248 gcc_jit_global_set_initializer_rvalue (foo
, ctor
);
250 { /* struct fi foo = {0, 0}; (null fields, null elements in values) */
251 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
253 GCC_JIT_GLOBAL_EXPORTED
,
255 "global_struct_fi_00_2");
257 gcc_jit_rvalue
*vals
[] = { 0, 0};
259 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_struct_constructor
266 gcc_jit_global_set_initializer_rvalue (foo
, ctor
);
268 { /* struct fi foo = {.i = 0} (null init);
271 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
273 GCC_JIT_GLOBAL_EXPORTED
,
275 "global_struct_fi_0_1");
277 gcc_jit_rvalue
*vals
[] = {0};
278 gcc_jit_field
*fields
[] = {fi_i
};
280 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_struct_constructor
286 gcc_jit_global_set_initializer_rvalue (foo
, ctor
);
288 { /* struct fi foo = {0};
291 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
293 GCC_JIT_GLOBAL_EXPORTED
,
295 "global_struct_fi_0_2");
297 gcc_jit_rvalue
*vals
[] = {0};
299 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_struct_constructor
305 gcc_jit_global_set_initializer_rvalue (foo
, ctor
);
307 { /* struct fi foo = {}; (null init)
309 Null fields and values. */
310 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
312 GCC_JIT_GLOBAL_EXPORTED
,
314 "global_struct_fi_6");
316 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_struct_constructor
322 gcc_jit_global_set_initializer_rvalue (foo
, ctor
);
324 { /* struct fi foo = {2 * 2, 3}; */
325 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
327 GCC_JIT_GLOBAL_EXPORTED
,
329 "global_struct_fi_3");
331 gcc_jit_rvalue
*fval
= gcc_jit_context_new_rvalue_from_int (
332 ctxt
, float_type
, 2);
333 gcc_jit_rvalue
*fval2
= gcc_jit_context_new_rvalue_from_int (
334 ctxt
, float_type
, 2);
335 gcc_jit_rvalue
*ival
= gcc_jit_context_new_rvalue_from_int (
337 gcc_jit_rvalue
*rval_mul
= gcc_jit_context_new_binary_op (ctxt
, 0,
338 GCC_JIT_BINARY_OP_MULT
,
343 gcc_jit_rvalue
*vals
[] = { rval_mul
, ival
};
344 gcc_jit_field
*fields
[] = {fi_f
, fi_i
};
346 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_struct_constructor
353 gcc_jit_global_set_initializer_rvalue (foo
, ctor
);
355 { /* union ubar foo = {.ff = 3}; */
356 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
358 GCC_JIT_GLOBAL_EXPORTED
,
360 "global_union_ufoo_ff3");
362 gcc_jit_rvalue
*fval
= gcc_jit_context_new_rvalue_from_int (
363 ctxt
, float_type
, 3);
365 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_union_constructor (
372 gcc_jit_global_set_initializer_rvalue (foo
, ctor
);
374 { /* union ubar foo = {.ii = 2}; */
375 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
377 GCC_JIT_GLOBAL_EXPORTED
,
379 "global_union_ufoo_ii2");
381 gcc_jit_rvalue
*ival
= gcc_jit_context_new_rvalue_from_int (
384 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_union_constructor (
391 gcc_jit_global_set_initializer_rvalue (foo
, ctor
);
393 { /* union ubar foo = {1.1f}; should init first field */
394 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
396 GCC_JIT_GLOBAL_EXPORTED
,
398 "global_union_ufoo_ff1c1");
400 gcc_jit_rvalue
*fval
= gcc_jit_context_new_rvalue_from_double (
401 ctxt
, float_type
, 1.1);
403 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_union_constructor (
410 gcc_jit_global_set_initializer_rvalue (foo
, ctor
);
412 { /* union ubar foo = (union ubar){}; */
413 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
415 GCC_JIT_GLOBAL_EXPORTED
,
417 "global_union_ufoo_0");
419 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_union_constructor (
426 gcc_jit_global_set_initializer_rvalue (foo
, ctor
);
429 gcc_jit_rvalue
*rval
= gcc_jit_context_new_rvalue_from_int (
431 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
433 GCC_JIT_GLOBAL_EXPORTED
,
436 gcc_jit_global_set_initializer_rvalue (foo
,
439 { /* const volatile int foo = 3; */
440 gcc_jit_rvalue
*rval
= gcc_jit_context_new_rvalue_from_int (
442 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
444 GCC_JIT_GLOBAL_EXPORTED
,
445 gcc_jit_type_get_const (gcc_jit_type_get_volatile (int_type
)),
447 gcc_jit_global_set_initializer_rvalue (foo
,
450 { /* Try the above, but with opposite order of global and literal calls */
451 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
453 GCC_JIT_GLOBAL_EXPORTED
,
456 gcc_jit_rvalue
*rval
= gcc_jit_context_new_rvalue_from_int (
458 gcc_jit_global_set_initializer_rvalue (foo
,
461 { /* int foo = 3 * (3 + 3) */
462 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
464 GCC_JIT_GLOBAL_EXPORTED
,
467 gcc_jit_rvalue
*rval3_0
= gcc_jit_context_new_rvalue_from_int (
469 gcc_jit_rvalue
*rval3_1
= gcc_jit_context_new_rvalue_from_int (
471 gcc_jit_rvalue
*rval3_2
= gcc_jit_context_new_rvalue_from_int (
473 gcc_jit_rvalue
*rval_plus
= gcc_jit_context_new_binary_op (ctxt
, 0,
474 GCC_JIT_BINARY_OP_PLUS
,
478 gcc_jit_rvalue
*rval_mul
= gcc_jit_context_new_binary_op (ctxt
, 0,
479 GCC_JIT_BINARY_OP_MULT
,
484 gcc_jit_global_set_initializer_rvalue (foo
,
487 { /* int foo = ~(-(((((2 | 8) & 15) ^ 0) << 3 >> 2 - 1) / 2)); */
488 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
490 GCC_JIT_GLOBAL_EXPORTED
,
492 "global_int_alotofoperators");
493 gcc_jit_rvalue
*rval_0
= gcc_jit_context_new_rvalue_from_int (
495 gcc_jit_rvalue
*rval_1
= gcc_jit_context_new_rvalue_from_int (
497 gcc_jit_rvalue
*rval_2
= gcc_jit_context_new_rvalue_from_int (
499 gcc_jit_rvalue
*rval_3
= gcc_jit_context_new_rvalue_from_int (
501 gcc_jit_rvalue
*rval_4
= gcc_jit_context_new_rvalue_from_int (
503 gcc_jit_rvalue
*rval_5
= gcc_jit_context_new_rvalue_from_int (
505 gcc_jit_rvalue
*rval_6
= gcc_jit_context_new_rvalue_from_int (
507 gcc_jit_rvalue
*rval_7
= gcc_jit_context_new_rvalue_from_int (
510 gcc_jit_rvalue
*rval_or
= gcc_jit_context_new_binary_op (ctxt
, 0,
511 GCC_JIT_BINARY_OP_BITWISE_OR
,
515 gcc_jit_rvalue
*rval_and
= gcc_jit_context_new_binary_op (ctxt
, 0,
516 GCC_JIT_BINARY_OP_BITWISE_AND
,
520 gcc_jit_rvalue
*rval_xor
= gcc_jit_context_new_binary_op (ctxt
, 0,
521 GCC_JIT_BINARY_OP_BITWISE_XOR
,
525 gcc_jit_rvalue
*rval_lsh
= gcc_jit_context_new_binary_op (ctxt
, 0,
526 GCC_JIT_BINARY_OP_LSHIFT
,
530 gcc_jit_rvalue
*rval_rsh
= gcc_jit_context_new_binary_op (ctxt
, 0,
531 GCC_JIT_BINARY_OP_RSHIFT
,
535 gcc_jit_rvalue
*rval_min
= gcc_jit_context_new_binary_op (ctxt
, 0,
536 GCC_JIT_BINARY_OP_MINUS
,
540 gcc_jit_rvalue
*rval_div
= gcc_jit_context_new_binary_op (ctxt
, 0,
541 GCC_JIT_BINARY_OP_DIVIDE
,
545 gcc_jit_rvalue
*rval_umin
= gcc_jit_context_new_unary_op (ctxt
, 0,
546 GCC_JIT_UNARY_OP_MINUS
,
549 gcc_jit_rvalue
*rval_neg
= gcc_jit_context_new_unary_op (ctxt
, 0,
550 GCC_JIT_UNARY_OP_BITWISE_NEGATE
,
554 gcc_jit_global_set_initializer_rvalue (foo
,
557 { /* int foo = 3; int *pfoo = &foo; */
558 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
560 GCC_JIT_GLOBAL_EXPORTED
,
563 gcc_jit_rvalue
*rval
= gcc_jit_context_new_rvalue_from_int (
565 gcc_jit_global_set_initializer_rvalue (foo
,
568 gcc_jit_lvalue
*pfoo
= gcc_jit_context_new_global (
570 GCC_JIT_GLOBAL_EXPORTED
,
573 gcc_jit_global_set_initializer_rvalue (pfoo
,
574 gcc_jit_lvalue_get_address (foo
, 0));
576 { /* static int foo; int *pfoo = &foo; */
577 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
579 GCC_JIT_GLOBAL_INTERNAL
,
583 gcc_jit_lvalue
*pfoo
= gcc_jit_context_new_global (
585 GCC_JIT_GLOBAL_EXPORTED
,
588 gcc_jit_global_set_initializer_rvalue (pfoo
,
589 gcc_jit_lvalue_get_address (foo
, 0));
591 gcc_jit_function
*fn
=
592 gcc_jit_context_new_function (ctxt
,
594 GCC_JIT_FUNCTION_EXPORTED
,
595 gcc_jit_type_get_pointer(int_type
),
601 gcc_jit_block
*block
= gcc_jit_function_new_block (fn
, "start");
603 gcc_jit_block_end_with_return (block
,
605 gcc_jit_lvalue_get_address (foo
, 0));
607 { /* int foo = 3; int *pfoo = &foo + 1; */
608 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
610 GCC_JIT_GLOBAL_EXPORTED
,
613 gcc_jit_rvalue
*rval
= gcc_jit_context_new_rvalue_from_int (
615 gcc_jit_global_set_initializer_rvalue (foo
,
618 gcc_jit_lvalue
*pfoo
= gcc_jit_context_new_global (
620 GCC_JIT_GLOBAL_EXPORTED
,
623 gcc_jit_global_set_initializer_rvalue (pfoo
,
624 gcc_jit_lvalue_get_address (
625 gcc_jit_context_new_array_access(
628 gcc_jit_lvalue_get_address(foo
, 0),
629 gcc_jit_context_one(ctxt
, int_type
)),
632 { /* double foo = 3; */
633 gcc_jit_lvalue
*double1
= gcc_jit_context_new_global (
635 GCC_JIT_GLOBAL_EXPORTED
,
638 gcc_jit_rvalue
*rval
= gcc_jit_context_new_rvalue_from_int (
639 ctxt
, double_type
, 3);
640 gcc_jit_global_set_initializer_rvalue (double1
,
643 { /* double foo = 3 * 3 + 3 */
644 gcc_jit_lvalue
*double1
= gcc_jit_context_new_global (
646 GCC_JIT_GLOBAL_EXPORTED
,
648 "global_double2_12");
649 gcc_jit_rvalue
*rval
= gcc_jit_context_new_rvalue_from_int (
650 ctxt
, double_type
, 3);
651 gcc_jit_rvalue
*rval_mul
= gcc_jit_context_new_binary_op (ctxt
, 0,
652 GCC_JIT_BINARY_OP_MULT
,
656 gcc_jit_rvalue
*rval_plus
= gcc_jit_context_new_binary_op (ctxt
, 0,
657 GCC_JIT_BINARY_OP_PLUS
,
661 gcc_jit_global_set_initializer_rvalue (double1
,
664 { /* bool foo = 3 + 3 <= 6; */
665 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
667 GCC_JIT_GLOBAL_EXPORTED
,
670 gcc_jit_rvalue
*rval3_0
= gcc_jit_context_new_rvalue_from_int (
672 gcc_jit_rvalue
*rval3_1
= gcc_jit_context_new_rvalue_from_int (
674 gcc_jit_rvalue
*rval6
= gcc_jit_context_new_rvalue_from_int (
676 gcc_jit_rvalue
*rval_plus
= gcc_jit_context_new_binary_op (ctxt
,
678 GCC_JIT_BINARY_OP_PLUS
,
682 gcc_jit_rvalue
*rval_le
= gcc_jit_context_new_comparison (ctxt
,
684 GCC_JIT_COMPARISON_LE
,
688 gcc_jit_global_set_initializer_rvalue (foo
,
691 gcc_jit_lvalue
*global_intarr_1234
;
692 { /* int foo[] = {1,2,3,4}; */
694 gcc_jit_type
*arr_type
= gcc_jit_context_new_array_type (ctxt
,
698 gcc_jit_rvalue
*rval_1
= gcc_jit_context_new_rvalue_from_int (
700 gcc_jit_rvalue
*rval_2
= gcc_jit_context_new_rvalue_from_int (
702 gcc_jit_rvalue
*rval_3
= gcc_jit_context_new_rvalue_from_int (
704 gcc_jit_rvalue
*rval_4
= gcc_jit_context_new_rvalue_from_int (
707 gcc_jit_rvalue
*values
[] = {rval_1
, rval_2
, rval_3
, rval_4
};
709 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_array_constructor (ctxt
,
714 global_intarr_1234
= gcc_jit_context_new_global (
716 GCC_JIT_GLOBAL_EXPORTED
,
718 "global_intarr_1234");
719 gcc_jit_global_set_initializer_rvalue (global_intarr_1234
, ctor
);
721 { /* float foo[4] = {1,2}; */
723 gcc_jit_type
*arr_type
= gcc_jit_context_new_array_type (ctxt
,
727 gcc_jit_rvalue
*rval_1
= gcc_jit_context_new_rvalue_from_int (
728 ctxt
, float_type
, 1);
729 gcc_jit_rvalue
*rval_2
= gcc_jit_context_new_rvalue_from_int (
730 ctxt
, float_type
, 2);
732 gcc_jit_rvalue
*values
[] = {rval_1
, rval_2
};
734 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_array_constructor (ctxt
,
739 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
741 GCC_JIT_GLOBAL_EXPORTED
,
743 "global_floatarr_12");
744 gcc_jit_global_set_initializer_rvalue (foo
, ctor
);
746 { /* float foo[4] = {1,2};
747 With different array objects of same size and type. */
749 gcc_jit_type
*arr_type
= gcc_jit_context_new_array_type (ctxt
,
753 gcc_jit_type
*arr_type1
= gcc_jit_context_new_array_type (ctxt
,
757 gcc_jit_rvalue
*rval_1
= gcc_jit_context_new_rvalue_from_int (
758 ctxt
, float_type
, 1);
759 gcc_jit_rvalue
*rval_2
= gcc_jit_context_new_rvalue_from_int (
760 ctxt
, float_type
, 2);
762 gcc_jit_rvalue
*values
[] = {rval_1
, rval_2
};
764 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_array_constructor (ctxt
,
769 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
771 GCC_JIT_GLOBAL_EXPORTED
,
773 "global_floatarr_12_2");
774 gcc_jit_global_set_initializer_rvalue (foo
, ctor
);
776 { /* float foo[4] = {1,2,0}; (null init) */
778 gcc_jit_type
*arr_type
= gcc_jit_context_new_array_type (ctxt
,
782 gcc_jit_rvalue
*rval_1
= gcc_jit_context_new_rvalue_from_int (
783 ctxt
, float_type
, 1);
784 gcc_jit_rvalue
*rval_2
= gcc_jit_context_new_rvalue_from_int (
785 ctxt
, float_type
, 2);
787 gcc_jit_rvalue
*values
[] = {rval_1
, rval_2
, 0};
789 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_array_constructor (ctxt
,
794 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
796 GCC_JIT_GLOBAL_EXPORTED
,
798 "global_floatarr_120");
799 gcc_jit_global_set_initializer_rvalue (foo
, ctor
);
801 { /* float foo[4] = {}; (null init) */
803 gcc_jit_type
*arr_type
= gcc_jit_context_new_array_type (ctxt
,
808 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_array_constructor (ctxt
,
813 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
815 GCC_JIT_GLOBAL_EXPORTED
,
817 "global_floatarr_0000");
818 gcc_jit_global_set_initializer_rvalue (foo
, ctor
);
820 { /* float foo[4] = {NULL , NULL, 3, NULL, 5, 6}; (null init) */
822 gcc_jit_type
*arr_type
= gcc_jit_context_new_array_type (ctxt
,
826 gcc_jit_rvalue
*rval3
= gcc_jit_context_new_rvalue_from_int (
827 ctxt
, float_type
, 3);
828 gcc_jit_rvalue
*rval5
= gcc_jit_context_new_rvalue_from_int (
829 ctxt
, float_type
, 5);
830 gcc_jit_rvalue
*rval6
= gcc_jit_context_new_rvalue_from_int (
831 ctxt
, float_type
, 6);
833 gcc_jit_rvalue
*values
[] = {0, 0, rval3
, 0, rval5
, rval6
, 0 };
835 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_array_constructor (ctxt
,
840 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
842 GCC_JIT_GLOBAL_EXPORTED
,
844 "global_floatarr_00305600");
845 gcc_jit_global_set_initializer_rvalue (foo
, ctor
);
847 { /* int *foo[4] = {0, &global_intarr_1234[1], 0}; */
849 gcc_jit_type
*arr_type
= gcc_jit_context_new_array_type (ctxt
,
853 gcc_jit_rvalue
*rval_1
= gcc_jit_context_new_rvalue_from_int (
855 gcc_jit_lvalue
*arr_access
= gcc_jit_context_new_array_access (
858 gcc_jit_lvalue_as_rvalue (global_intarr_1234
),
860 gcc_jit_rvalue
*rval_2
= gcc_jit_lvalue_get_address (arr_access
, 0);
861 gcc_jit_rvalue
*rval_3
= gcc_jit_context_null (ctxt
, pint_type
);
863 gcc_jit_rvalue
*values
[] = {0, rval_2
, rval_3
};
865 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_array_constructor (ctxt
,
870 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
872 GCC_JIT_GLOBAL_EXPORTED
,
874 "global_pintarr_x2xx");
875 gcc_jit_global_set_initializer_rvalue (foo
, ctor
);
877 { /* char foo[4] = {'q','w','e',0}; */
879 gcc_jit_type
*arr_type
= gcc_jit_context_new_array_type (ctxt
,
885 gcc_jit_rvalue
*rvals
[] = {
886 gcc_jit_context_new_rvalue_from_int ( ctxt
, char_type
, 'q'),
887 gcc_jit_context_new_rvalue_from_int ( ctxt
, char_type
, 'w'),
888 gcc_jit_context_new_rvalue_from_int ( ctxt
, char_type
, 'e'),
889 gcc_jit_context_new_rvalue_from_int ( ctxt
, char_type
, 0)
892 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_array_constructor (ctxt
,
897 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
899 GCC_JIT_GLOBAL_EXPORTED
,
901 "global_chararr_qwe");
902 gcc_jit_global_set_initializer_rvalue (foo
, ctor
);
904 { /* int foo[2][2] = {{1,2},{3,4}}; */
906 gcc_jit_type
*row_type
= gcc_jit_context_new_array_type (ctxt
,
911 gcc_jit_type
*arr_type
= gcc_jit_context_new_array_type (ctxt
,
915 gcc_jit_rvalue
*rvals_row0
[] = {
916 gcc_jit_context_new_rvalue_from_int ( ctxt
, int_type
, 1),
917 gcc_jit_context_new_rvalue_from_int ( ctxt
, int_type
, 2)
919 gcc_jit_rvalue
*rvals_row1
[] = {
920 gcc_jit_context_new_rvalue_from_int ( ctxt
, int_type
, 3),
921 gcc_jit_context_new_rvalue_from_int ( ctxt
, int_type
, 4)
924 gcc_jit_rvalue
*ctor_row0
=
925 gcc_jit_context_new_array_constructor (ctxt
,
930 gcc_jit_rvalue
*ctor_row1
=
931 gcc_jit_context_new_array_constructor (ctxt
,
936 gcc_jit_rvalue
*ctors_row
[] = {ctor_row0
, ctor_row1
};
938 gcc_jit_rvalue
*ctor_arr
=
939 gcc_jit_context_new_array_constructor (ctxt
,
945 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
947 GCC_JIT_GLOBAL_EXPORTED
,
949 "global_int2x2matrix_1234");
951 gcc_jit_global_set_initializer_rvalue (foo
, ctor_arr
);
953 { /* const char *foo[4] = {"qwe", "asd"}; */
955 gcc_jit_type
*arr_type
= gcc_jit_context_new_array_type (ctxt
,
961 gcc_jit_rvalue
*rvals
[] = {
962 gcc_jit_context_new_string_literal (ctxt
, "qwe"),
963 gcc_jit_context_new_string_literal (ctxt
, "asd")
966 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_array_constructor (ctxt
,
971 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
973 GCC_JIT_GLOBAL_EXPORTED
,
975 "global_cpchararr_qwe_asd");
976 gcc_jit_global_set_initializer_rvalue (foo
, ctor
);
978 { /* const int foo = 3;
981 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
983 GCC_JIT_GLOBAL_EXPORTED
,
984 gcc_jit_type_get_const (int_type
),
985 "global_const_int_3");
986 gcc_jit_rvalue
*rval3
= gcc_jit_context_new_rvalue_from_int (
988 gcc_jit_global_set_initializer_rvalue (foo
,
990 gcc_jit_lvalue
*bar
= gcc_jit_context_new_global (
992 GCC_JIT_GLOBAL_EXPORTED
,
994 "global_lvalueinit_int_3");
995 gcc_jit_global_set_initializer_rvalue (bar
,
996 gcc_jit_lvalue_as_rvalue (foo
));
998 { /* int foo = 3 * 2;
999 int arr[] = {1,2,3,4};
1000 int *bar = &arr[2] + 1
1002 Example in the docs.
1005 gcc_jit_type
*arr_type
= gcc_jit_context_new_array_type (ctxt
,
1009 gcc_jit_rvalue
*rval_1
= gcc_jit_context_new_rvalue_from_int (
1011 gcc_jit_rvalue
*rval_2
= gcc_jit_context_new_rvalue_from_int (
1013 gcc_jit_rvalue
*rval_3
= gcc_jit_context_new_rvalue_from_int (
1015 gcc_jit_rvalue
*rval_4
= gcc_jit_context_new_rvalue_from_int (
1018 gcc_jit_rvalue
*values
[] = {rval_1
, rval_2
, rval_3
, rval_4
};
1020 gcc_jit_rvalue
*ctor
= gcc_jit_context_new_array_constructor (ctxt
,
1025 gcc_jit_lvalue
*global_intarr_1234
=
1026 gcc_jit_context_new_global (ctxt
, NULL
,
1027 GCC_JIT_GLOBAL_EXPORTED
,
1029 "global_intarr_1234_2");
1031 gcc_jit_global_set_initializer_rvalue (global_intarr_1234
, ctor
);
1033 gcc_jit_lvalue
*bar
=
1034 gcc_jit_context_new_global (ctxt
, NULL
,
1035 GCC_JIT_GLOBAL_EXPORTED
,
1038 gcc_jit_global_set_initializer_rvalue
1040 gcc_jit_context_new_binary_op
1041 (ctxt
, 0, GCC_JIT_BINARY_OP_MULT
,
1043 gcc_jit_context_new_rvalue_from_int (ctxt
, int_type
, 3),
1044 gcc_jit_context_new_rvalue_from_int (ctxt
, int_type
, 2)));
1046 gcc_jit_lvalue
*pfoo
=
1047 gcc_jit_context_new_global (ctxt
, NULL
,
1048 GCC_JIT_GLOBAL_EXPORTED
,
1049 gcc_jit_type_get_pointer (int_type
),
1051 /* int *bar = &arr[2] + 1;
1053 In practice we could just do &foo[3]
1054 but just prove folding this works. */
1055 gcc_jit_global_set_initializer_rvalue (
1057 gcc_jit_lvalue_get_address (
1058 gcc_jit_context_new_array_access (
1060 gcc_jit_lvalue_get_address (
1061 gcc_jit_context_new_array_access (
1063 gcc_jit_lvalue_as_rvalue (global_intarr_1234
),
1064 gcc_jit_context_new_rvalue_from_int (ctxt
, int_type
, 2)),
1066 gcc_jit_context_new_rvalue_from_int (ctxt
, int_type
, 1)),
1069 { /* static int bar = 11;
1070 int foo () { return bar; } */
1072 gcc_jit_lvalue
*bar
= gcc_jit_context_new_global (
1074 GCC_JIT_GLOBAL_INTERNAL
,
1076 "global_static_int_11");
1077 gcc_jit_rvalue
*rval1
= gcc_jit_context_new_rvalue_from_int (
1078 ctxt
, int_type
, 11);
1079 gcc_jit_global_set_initializer_rvalue (bar
,
1082 gcc_jit_function
*fn11
=
1083 gcc_jit_context_new_function (ctxt
,
1085 GCC_JIT_FUNCTION_EXPORTED
,
1091 gcc_jit_block
*block
= gcc_jit_function_new_block (fn11
, "start");
1093 gcc_jit_block_end_with_return (block
,
1095 gcc_jit_lvalue_as_rvalue(bar
));
1097 { /* static const int cbar = 11;
1098 int cfoo () { return cbar; } */
1100 gcc_jit_lvalue
*bar
= gcc_jit_context_new_global (
1102 GCC_JIT_GLOBAL_INTERNAL
,
1103 gcc_jit_type_get_const (int_type
),
1104 "global_static_cint_11");
1105 gcc_jit_rvalue
*rval1
= gcc_jit_context_new_rvalue_from_int (
1106 ctxt
, int_type
, 11);
1107 gcc_jit_global_set_initializer_rvalue (bar
,
1110 gcc_jit_function
*fn11
=
1111 gcc_jit_context_new_function (ctxt
,
1113 GCC_JIT_FUNCTION_EXPORTED
,
1119 gcc_jit_block
*block
= gcc_jit_function_new_block (fn11
, "start");
1121 gcc_jit_block_end_with_return (block
,
1123 gcc_jit_lvalue_as_rvalue(bar
));
1125 { /* static const int cbar = 12;
1126 const int* cfoo () { return &cbar; } */
1128 gcc_jit_lvalue
*bar
= gcc_jit_context_new_global (
1130 GCC_JIT_GLOBAL_INTERNAL
,
1131 gcc_jit_type_get_const (int_type
),
1132 "global_static_cint_12");
1133 gcc_jit_rvalue
*rval1
= gcc_jit_context_new_rvalue_from_int (
1134 ctxt
, int_type
, 12);
1135 gcc_jit_global_set_initializer_rvalue (bar
,
1138 gcc_jit_function
*fn11
=
1139 gcc_jit_context_new_function (ctxt
,
1141 GCC_JIT_FUNCTION_EXPORTED
,
1142 gcc_jit_type_get_pointer(int_type
),
1148 gcc_jit_block
*block
= gcc_jit_function_new_block (fn11
, "start");
1150 gcc_jit_block_end_with_return (block
,
1152 gcc_jit_lvalue_get_address (bar
, 0));
1154 { /* const int foo = 3;
1155 short bar = (short)foo;
1159 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
1161 GCC_JIT_GLOBAL_EXPORTED
,
1162 gcc_jit_type_get_const (int_type
),
1163 "global_const_int_4");
1164 gcc_jit_rvalue
*rval3
= gcc_jit_context_new_rvalue_from_int (
1166 gcc_jit_global_set_initializer_rvalue (foo
,
1168 gcc_jit_lvalue
*bar
= gcc_jit_context_new_global (
1170 GCC_JIT_GLOBAL_EXPORTED
,
1172 "global_lvalueinit_short_3");
1173 gcc_jit_global_set_initializer_rvalue (
1175 gcc_jit_context_new_cast( ctxt
, 0,
1176 gcc_jit_lvalue_as_rvalue (foo
),
1179 { /* const int foo = 3;
1180 const int const *bar = &foo; */
1181 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
1183 GCC_JIT_GLOBAL_EXPORTED
,
1184 gcc_jit_type_get_const (int_type
),
1185 "global_const_int_6");
1186 gcc_jit_rvalue
*rval3
= gcc_jit_context_new_rvalue_from_int (
1188 gcc_jit_global_set_initializer_rvalue (foo
,
1190 gcc_jit_lvalue
*bar
= gcc_jit_context_new_global (
1192 GCC_JIT_GLOBAL_EXPORTED
,
1193 gcc_jit_type_get_const (
1194 gcc_jit_type_get_pointer (
1195 gcc_jit_type_get_const (
1197 "global_lvalueinit_cpcint_3");
1198 gcc_jit_global_set_initializer_rvalue (
1200 gcc_jit_lvalue_get_address (foo
, 0));
1202 { /* const int __attribute__ ((aligned (64))) foo = 3;
1205 Assure alignement does not make the constant "miss"
1206 or something strange.
1208 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
1210 GCC_JIT_GLOBAL_EXPORTED
,
1211 gcc_jit_type_get_const (gcc_jit_type_get_aligned (int_type
, 64)),
1212 "global_const_int_7");
1213 gcc_jit_rvalue
*rval
= gcc_jit_context_new_rvalue_from_int (
1215 gcc_jit_global_set_initializer_rvalue (foo
,
1217 gcc_jit_lvalue
*bar
= gcc_jit_context_new_global (
1219 GCC_JIT_GLOBAL_EXPORTED
,
1221 "global_lvalueinit_int_4");
1222 gcc_jit_global_set_initializer_rvalue (bar
,
1223 gcc_jit_lvalue_as_rvalue (foo
));
1226 /* union upintsize { size_t s; int *p } u = {.s = 0xEEEFBEEF}; */
1227 gcc_jit_field
*f1
= gcc_jit_context_new_field (ctxt
,
1231 gcc_jit_field
*f2
= gcc_jit_context_new_field (ctxt
,
1235 gcc_jit_field
*fields1
[] = {f1
, f2
};
1237 gcc_jit_type
*ubar
= gcc_jit_context_new_union_type (ctxt
,
1242 gcc_jit_lvalue
*foo
= gcc_jit_context_new_global (
1244 GCC_JIT_GLOBAL_EXPORTED
,
1245 gcc_jit_type_get_const (ubar
),
1246 "global_const_upintsize_1");
1248 gcc_jit_rvalue
*val
= gcc_jit_context_new_rvalue_from_long (
1249 ctxt
, size_type
, 0xEEEFBEEF);
1251 gcc_jit_rvalue
*ctor
=
1252 gcc_jit_context_new_union_constructor (ctxt
,
1258 gcc_jit_global_set_initializer_rvalue (foo
, ctor
);
1265 struct A a = {.b = b};
1266 struct B b = {.a = a};
1268 See that opaque structs and circular pointers works.
1271 gcc_jit_struct
*struct_B
=
1272 gcc_jit_context_new_opaque_struct(ctxt
,
1275 gcc_jit_field
*fields_A
[] =
1277 gcc_jit_context_new_field (ctxt
, 0,
1278 gcc_jit_type_get_pointer (
1279 gcc_jit_struct_as_type (struct_B
)),
1283 gcc_jit_struct
*struct_A
=
1284 gcc_jit_context_new_struct_type(ctxt
, 0, "A", 1, fields_A
);
1286 gcc_jit_field
*fields_B
[] =
1288 gcc_jit_context_new_field (ctxt
, 0,
1289 gcc_jit_type_get_pointer (
1290 gcc_jit_struct_as_type (struct_A
)),
1294 gcc_jit_struct_set_fields (struct_B
, 0, 1, fields_B
);
1297 gcc_jit_context_new_global (ctxt
, 0, GCC_JIT_GLOBAL_EXPORTED
,
1298 gcc_jit_struct_as_type (struct_A
),
1301 gcc_jit_context_new_global (ctxt
, 0, GCC_JIT_GLOBAL_EXPORTED
,
1302 gcc_jit_struct_as_type (struct_B
),
1304 gcc_jit_rvalue
*b_addr
= gcc_jit_lvalue_get_address( b
, 0);
1305 gcc_jit_rvalue
*a_ctor
=
1306 gcc_jit_context_new_struct_constructor (ctxt
, 0,
1307 gcc_jit_struct_as_type (struct_A
),
1310 gcc_jit_rvalue
*a_addr
= gcc_jit_lvalue_get_address( a
, 0);
1311 gcc_jit_rvalue
*b_ctor
=
1312 gcc_jit_context_new_struct_constructor (ctxt
, 0,
1313 gcc_jit_struct_as_type (struct_B
),
1317 gcc_jit_global_set_initializer_rvalue(a
, a_ctor
);
1318 gcc_jit_global_set_initializer_rvalue(b
, b_ctor
);
1351 int test_aligned64_works_in_linker_1
__attribute__ ((aligned (64))) = 0;
1352 int test_aligned64_works_in_linker_2
__attribute__ ((aligned (64))) = 0;
1355 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
1357 CHECK_NON_NULL (result
);
1361 gcc_jit_result_get_global (result
, "global_struct_bar_1234_1");
1363 CHECK_VALUE (bar
->ff
, 1);
1364 CHECK_VALUE (bar
->fi
.f
, 2);
1365 CHECK_VALUE (bar
->fi
.i
, 3);
1366 CHECK_VALUE (bar
->ii
, 4);
1370 gcc_jit_result_get_global (result
, "global_struct_bar_1234_2");
1372 CHECK_VALUE (bar
->ff
, 1);
1373 CHECK_VALUE (bar
->fi
.f
, 2);
1374 CHECK_VALUE (bar
->fi
.i
, 3);
1375 CHECK_VALUE (bar
->ii
, 4);
1378 struct fi
*fi
= gcc_jit_result_get_global (result
, "global_struct_fi_23_1");
1380 CHECK_VALUE (fi
->f
, 2);
1381 CHECK_VALUE (fi
->i
, 3);
1384 struct fi
*fi
= gcc_jit_result_get_global (result
, "global_struct_fi_23_2");
1386 CHECK_VALUE (fi
->f
, 2);
1387 CHECK_VALUE (fi
->i
, 3);
1390 struct fi
*fi
= gcc_jit_result_get_global (result
, "global_struct_fi_00_1");
1392 CHECK_VALUE (fi
->f
, 0);
1393 CHECK_VALUE (fi
->i
, 0);
1396 struct fi
*fi
= gcc_jit_result_get_global (result
, "global_struct_fi_00_2");
1398 CHECK_VALUE (fi
->f
, 0);
1399 CHECK_VALUE (fi
->i
, 0);
1402 struct fi
*fi
= gcc_jit_result_get_global (result
, "global_struct_fi_0_1");
1404 CHECK_VALUE (fi
->f
, 0);
1405 CHECK_VALUE (fi
->i
, 0);
1408 struct fi
*fi
= gcc_jit_result_get_global (result
, "global_struct_fi_0_2");
1410 CHECK_VALUE (fi
->f
, 0);
1411 CHECK_VALUE (fi
->i
, 0);
1414 struct fi
*fi
= gcc_jit_result_get_global (result
, "global_struct_fi_6");
1416 CHECK_VALUE (fi
->f
, 0);
1417 CHECK_VALUE (fi
->i
, 0);
1420 struct fi
*fi
= gcc_jit_result_get_global (result
, "global_struct_fi_3");
1422 CHECK_VALUE (fi
->f
, 2 * 2);
1423 CHECK_VALUE (fi
->i
, 3);
1426 union ubar1
*foo
= gcc_jit_result_get_global (result
,
1427 "global_union_ufoo_ff3");
1428 CHECK_VALUE (foo
->ff
, 3);
1431 union ubar1
*foo
= gcc_jit_result_get_global (result
,
1432 "global_union_ufoo_ii2");
1433 CHECK_VALUE (foo
->ii
, 2);
1436 union ubar1
*foo
= gcc_jit_result_get_global (result
,
1437 "global_union_ufoo_ff1c1");
1438 CHECK_VALUE (foo
->ff
, 1.1f
);
1441 union ubar1
*foo
= gcc_jit_result_get_global (result
,
1442 "global_union_ufoo_0");
1443 CHECK_VALUE (foo
->ii
, 0);
1446 int *foo
= gcc_jit_result_get_global (result
, "global_int1_3");
1448 CHECK_VALUE (*foo
, 3);
1451 int *foo
= gcc_jit_result_get_global (result
, "global_cvint1_3");
1453 CHECK_VALUE (*foo
, 3);
1456 int *foo
= gcc_jit_result_get_global (result
, "global_int2_3");
1458 CHECK_VALUE (*foo
, 3);
1461 int *foo
= gcc_jit_result_get_global (result
, "global_int3_18");
1463 CHECK_VALUE (*foo
, 18);
1466 int *foo
= gcc_jit_result_get_global (result
, "global_int_alotofoperators");
1468 CHECK_VALUE (*foo
, ~(-((((((2 | 8) & 15) ^ 0) << 3 >> 2) - 1) / 2)));
1471 int *foo
= gcc_jit_result_get_global (result
, "global_int4_3");
1472 int **pfoo
= gcc_jit_result_get_global (result
, "global_pint5");
1474 CHECK_VALUE (*foo
, 3);
1475 CHECK_VALUE (foo
, *pfoo
);
1476 CHECK_VALUE (**pfoo
, 3);
1479 int * (*foo
) (void) = gcc_jit_result_get_code (result
, "fn_pint_0");
1480 int **pfoo
= gcc_jit_result_get_global (result
, "global_pint6");
1482 CHECK_VALUE (*foo (), 0);
1483 CHECK_VALUE (foo (), *pfoo
);
1484 CHECK_VALUE (**pfoo
, 0);
1487 int *foo
= gcc_jit_result_get_global (result
, "global_int6_3");
1488 int **pfoo
= gcc_jit_result_get_global (result
, "global_pint7");
1490 CHECK_VALUE (*foo
, 3);
1491 CHECK_VALUE (foo
+ 1, *pfoo
);
1492 CHECK_VALUE (*(*pfoo
- 1), 3);
1495 double *foo
= gcc_jit_result_get_global (result
, "global_double1_3");
1497 CHECK_VALUE (*foo
, 3);
1500 double *foo
= gcc_jit_result_get_global (result
, "global_double2_12");
1502 CHECK_VALUE (*foo
, 12);
1505 _Bool
*foo
= gcc_jit_result_get_global (result
, "global_bool1_1");
1507 CHECK_VALUE (*foo
, 1);
1510 int *foo
= gcc_jit_result_get_global (result
, "global_intarr_1234");
1512 CHECK_VALUE (foo
[0], 1);
1513 CHECK_VALUE (foo
[1], 2);
1514 CHECK_VALUE (foo
[2], 3);
1515 CHECK_VALUE (foo
[3], 4);
1518 float *foo
= gcc_jit_result_get_global (result
, "global_floatarr_12");
1520 CHECK_VALUE (foo
[0], 1);
1521 CHECK_VALUE (foo
[1], 2);
1522 CHECK_VALUE (foo
[2], 0);
1523 CHECK_VALUE (foo
[3], 0);
1526 float *foo
= gcc_jit_result_get_global (result
, "global_floatarr_12_2");
1528 CHECK_VALUE (foo
[0], 1);
1529 CHECK_VALUE (foo
[1], 2);
1530 CHECK_VALUE (foo
[2], 0);
1531 CHECK_VALUE (foo
[3], 0);
1534 float *foo
= gcc_jit_result_get_global (result
, "global_floatarr_120");
1536 CHECK_VALUE (foo
[0], 1);
1537 CHECK_VALUE (foo
[1], 2);
1538 CHECK_VALUE (foo
[2], 0);
1539 CHECK_VALUE (foo
[3], 0);
1542 float *foo
= gcc_jit_result_get_global (result
, "global_floatarr_0000");
1544 CHECK_VALUE (foo
[0], 0);
1545 CHECK_VALUE (foo
[1], 0);
1546 CHECK_VALUE (foo
[2], 0);
1547 CHECK_VALUE (foo
[3], 0);
1550 float *foo
= gcc_jit_result_get_global (result
, "global_floatarr_00305600");
1552 float key
[] = {0,0,3,0,5,6,0,0};
1554 CHECK_VALUE (memcmp (foo
, key
, sizeof key
), 0);
1557 int **foo
= gcc_jit_result_get_global (result
, "global_pintarr_x2xx");
1559 CHECK_VALUE (foo
[0], 0);
1560 CHECK_VALUE (*foo
[1], 2);
1563 char *foo
= gcc_jit_result_get_global (result
, "global_chararr_qwe");
1564 const char *key
= "qwe";
1565 CHECK_VALUE (strcmp (foo
, key
), 0);
1568 int *foo
= gcc_jit_result_get_global (result
, "global_int2x2matrix_1234");
1570 for (int i
= 0; i
< 4; i
++)
1571 CHECK_VALUE (foo
[i
], i
+ 1);
1575 gcc_jit_result_get_global (result
, "global_cpchararr_qwe_asd");
1577 CHECK_VALUE (strcmp (foo
[0], "qwe"), 0);
1578 CHECK_VALUE (strcmp (foo
[1], "asd"), 0);
1581 int *foo
= gcc_jit_result_get_global (result
, "global_lvalueinit_int_3");
1583 CHECK_VALUE (*foo
, 3);
1587 gcc_jit_result_get_global (result
, "global_pint_4");
1589 gcc_jit_result_get_global (result
, "global_int_6");
1590 CHECK_VALUE (**pint
, 4);
1591 CHECK_VALUE (*foo
, 6);
1594 int (*fn
)(void) = gcc_jit_result_get_code (result
, "fn_int_11");
1595 CHECK_VALUE (fn (), 11);
1598 int (*fn
)(void) = gcc_jit_result_get_code (result
, "fn_cint_11");
1599 CHECK_VALUE (fn (), 11);
1602 int *(*fn
)(void) = gcc_jit_result_get_code (result
, "fn_cint_12");
1603 CHECK_VALUE (*fn (), 12);
1607 gcc_jit_result_get_code (result
, "global_lvalueinit_short_3");
1608 CHECK_VALUE (*foo
, 3);
1612 gcc_jit_result_get_code (result
, "global_lvalueinit_cpcint_3");
1613 CHECK_VALUE (**foo
, 3);
1617 gcc_jit_result_get_code (result
, "global_lvalueinit_int_4");
1618 CHECK_VALUE (*foo
, 4);
1621 gcc_jit_result_get_code (result
, "global_const_int_7");
1622 CHECK_VALUE (*bar
, 4);
1623 /* The linker does not have to support up to 64 alignment, so test that
1624 it does before testing that it works in libgccjit. */
1625 if ((size_t) &test_aligned64_works_in_linker_1
% 64 == 0 &&
1626 (size_t) &test_aligned64_works_in_linker_2
% 64 == 0)
1627 CHECK_VALUE ((size_t) bar
% 64, 0); /* __attribute__ ((aligned (64))) */
1630 union upintsize
*foo
=
1631 gcc_jit_result_get_code (result
, "global_const_upintsize_1");
1632 CHECK_VALUE (foo
->p
, (void*)0xEEEFBEEF);
1636 gcc_jit_result_get_code (result
, "a_glb");
1638 gcc_jit_result_get_code (result
, "b_glb");
1640 CHECK_VALUE (a
->b
, b
);
1641 CHECK_VALUE (b
->a
, a
);