21 create_code (gcc_jit_context
*ctxt
, void *user_data
)
23 /* Let's try to inject the equivalent of:
25 test_bogus_access (struct foo f)
29 i.e. using the wrong struct for the LHS.
31 gcc_jit_type
*void_type
=
32 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_VOID
);
33 gcc_jit_type
*int_type
=
34 gcc_jit_context_get_type (ctxt
, GCC_JIT_TYPE_INT
);
36 /* Map "struct foo". */
38 gcc_jit_context_new_field (ctxt
,
43 gcc_jit_context_new_field (ctxt
,
47 gcc_jit_field
*foo_fields
[] = {x
, y
};
48 gcc_jit_struct
*struct_foo
=
49 gcc_jit_context_new_struct_type (ctxt
, NULL
, "foo", 2, foo_fields
);
51 /* Map "struct bar". */
53 gcc_jit_context_new_field (ctxt
,
58 gcc_jit_context_new_field (ctxt
,
62 /* We don't actually need a gcc_jit_type for "struct bar" for the test. */
63 gcc_jit_field
*bar_fields
[] = {p
, q
};
64 (void)gcc_jit_context_new_struct_type (ctxt
, NULL
, "foo", 2, bar_fields
);
66 /* Build the test function. */
67 gcc_jit_param
*param_f
=
68 gcc_jit_context_new_param (ctxt
, NULL
,
69 gcc_jit_struct_as_type (struct_foo
), "f");
70 gcc_jit_function
*test_fn
=
71 gcc_jit_context_new_function (ctxt
, NULL
,
72 GCC_JIT_FUNCTION_EXPORTED
,
78 /* Erroneous: f.p = ... */
79 gcc_jit_lvalue
*lvalue
=
80 gcc_jit_lvalue_access_field (
81 gcc_jit_param_as_lvalue (param_f
),
86 gcc_jit_rvalue
*rvalue
=
87 gcc_jit_lvalue_as_rvalue (
88 gcc_jit_lvalue_access_field (
89 gcc_jit_param_as_lvalue (param_f
),
93 gcc_jit_block
*block
=
94 gcc_jit_function_new_block (test_fn
, NULL
);
95 gcc_jit_block_add_assignment (
99 gcc_jit_block_end_with_void_return (block
, NULL
);
103 verify_code (gcc_jit_context
*ctxt
, gcc_jit_result
*result
)
105 CHECK_VALUE (result
, NULL
);
107 /* Verify that the correct error message was emitted. */
108 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt
),
109 "gcc_jit_lvalue_access_field:"
110 " p is not a field of struct foo");