Preserve SSA info for more propagated copy
[official-gcc.git] / gcc / testsuite / jit.dg / test-pr105812-bool-operations.c
blob1daa1c3c35a13ec40a39b1c01dc3d1f9d4361003
1 #include "libgccjit.h"
3 #include "harness.h"
5 void
6 create_code (gcc_jit_context *ctxt, void *user_data)
8 gcc_jit_type* bool_type =
9 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_BOOL);
10 gcc_jit_type* bool_ptr_type =
11 gcc_jit_type_get_pointer (gcc_jit_type_get_aligned (bool_type, 1));
13 /* Function 1 */
15 gcc_jit_param* param1 = gcc_jit_context_new_param (ctxt, NULL, bool_type,
16 "param1");
17 gcc_jit_function* function1 =
18 gcc_jit_context_new_function (ctxt, NULL,
19 GCC_JIT_FUNCTION_EXPORTED, bool_type,
20 "function1", 1, &param1, 0);
21 gcc_jit_block* block1 = gcc_jit_function_new_block (function1, "start1");
23 gcc_jit_lvalue* var1 =
24 gcc_jit_function_new_local (function1, NULL, bool_type, "var1");
25 gcc_jit_rvalue* addr1 =
26 gcc_jit_lvalue_get_address (var1, NULL);
27 gcc_jit_rvalue* ptr1 =
28 gcc_jit_context_new_cast (ctxt, NULL, addr1, bool_ptr_type);
29 gcc_jit_lvalue* deref1 =
30 gcc_jit_rvalue_dereference (ptr1, NULL);
31 gcc_jit_rvalue* param1_rvalue =
32 gcc_jit_param_as_rvalue (param1);
33 gcc_jit_block_add_assignment (block1, NULL, deref1, param1_rvalue);
35 gcc_jit_rvalue* one = gcc_jit_context_one (ctxt, bool_type);
36 gcc_jit_block_end_with_return (block1, NULL, one);
38 /* Function 2 */
40 gcc_jit_param* param2 = gcc_jit_context_new_param (ctxt, NULL, bool_type,
41 "param2");
42 gcc_jit_function* function2 =
43 gcc_jit_context_new_function (ctxt, NULL,
44 GCC_JIT_FUNCTION_EXPORTED, bool_type,
45 "function2", 1, &param2, 0);
46 gcc_jit_block* block2 = gcc_jit_function_new_block (function2, "start2");
48 gcc_jit_lvalue* var2 =
49 gcc_jit_function_new_local (function2, NULL, bool_type, "var2");
50 gcc_jit_rvalue* addr2 =
51 gcc_jit_lvalue_get_address (var2, NULL);
52 gcc_jit_rvalue* ptr2 =
53 gcc_jit_context_new_cast (ctxt, NULL, addr2, bool_ptr_type);
54 gcc_jit_lvalue* deref2 =
55 gcc_jit_rvalue_dereference (ptr2, NULL);
56 gcc_jit_rvalue* param2_rvalue =
57 gcc_jit_param_as_rvalue (param2);
58 gcc_jit_block_add_assignment (block2, NULL, deref2, param2_rvalue);
60 gcc_jit_lvalue* return_value =
61 gcc_jit_function_new_local (function2, NULL, bool_type, "return_value");
62 gcc_jit_rvalue* call =
63 gcc_jit_context_new_call (ctxt, NULL, function1, 1, &param2_rvalue);
64 gcc_jit_block_add_assignment (block2, NULL, return_value, call);
66 gcc_jit_block* block2_1 =
67 gcc_jit_function_new_block (function2, "end2");
68 gcc_jit_block_end_with_jump (block2, NULL, block2_1);
70 gcc_jit_rvalue* value =
71 gcc_jit_context_new_unary_op (ctxt, NULL,
72 GCC_JIT_UNARY_OP_LOGICAL_NEGATE, bool_type,
73 param2_rvalue);
74 gcc_jit_rvalue* return_rvalue =
75 gcc_jit_lvalue_as_rvalue (return_value);
76 gcc_jit_rvalue* and =
77 gcc_jit_context_new_binary_op (ctxt, NULL,
78 GCC_JIT_BINARY_OP_BITWISE_AND, bool_type,
79 return_rvalue, value);
81 gcc_jit_block_end_with_return (block2_1, NULL, and);
84 extern void
85 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
87 /* Verify that no errors were emitted. */
88 CHECK_NON_NULL (result);