15 create_code (gcc_jit_context
*ctxt
, void *user_data
)
17 /* Let's try to inject the equivalent of:
19 test_bogus_dereference ()
24 i.e. where tmp is *not* a pointer.
26 gcc_jit_type
*void_type
=
27 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_VOID
);
28 gcc_jit_type
*int_type
=
29 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_INT
);
31 /* Map "struct foo". */
33 gcc_jit_context_new_field (ctxt
,
38 gcc_jit_context_new_field (ctxt
,
42 gcc_jit_field
*foo_fields
[] = {x
, y
};
43 gcc_jit_struct
*struct_foo
=
44 gcc_jit_context_new_struct_type (ctxt
, NULL
, "foo", 2, foo_fields
);
46 /* Build the test function. */
47 gcc_jit_function
*test_fn
=
48 gcc_jit_context_new_function (ctxt
, NULL
,
49 GCC_JIT_FUNCTION_EXPORTED
,
51 "test_bogus_dereference",
55 gcc_jit_function_new_local (test_fn
, NULL
,
56 gcc_jit_struct_as_type (struct_foo
),
59 gcc_jit_block
*block
= gcc_jit_function_new_block (test_fn
, NULL
);
61 /* Erroneous: tmp->x = ... */
62 gcc_jit_lvalue
*lvalue
=
63 gcc_jit_rvalue_dereference_field (
64 gcc_jit_lvalue_as_rvalue (tmp
),
68 /* Erroneous: ... = tmp->y; */
69 gcc_jit_rvalue
*rvalue
=
70 gcc_jit_lvalue_as_rvalue (
71 gcc_jit_rvalue_dereference_field (
72 gcc_jit_lvalue_as_rvalue (tmp
),
76 gcc_jit_block_add_assignment (
81 gcc_jit_block_end_with_void_return (block
, NULL
);
85 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
87 CHECK_VALUE (result
, NULL
);
89 /* Verify that the correct error message was emitted. */
90 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt
),
91 ("gcc_jit_rvalue_dereference_field:"
92 " dereference of non-pointer tmp (type: struct foo)"
93 " when accessing ->x"));