libgomp: Document 'GOMP_teams4'
[official-gcc.git] / gcc / testsuite / jit.dg / test-error-bad-bitcast2.c
blob602ae4070761df7d391cab5d1f420d66c0b3a6df
1 #include <stdlib.h>
2 #include <stdio.h>
4 #include "libgccjit.h"
6 #include "harness.h"
8 void
9 create_code (gcc_jit_context *ctxt, void *user_data)
11 /* Let's try to inject the equivalent of:
13 char[4096]
14 test_fn ()
16 int f;
17 return bitcast(f, char[4096]);
20 and verify that the API complains about the bad cast.
22 gcc_jit_type *int_type =
23 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
24 gcc_jit_type *char_type =
25 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_CHAR);
28 gcc_jit_type *array_type =
29 gcc_jit_context_new_array_type (ctxt, NULL, char_type, 4096);
31 gcc_jit_function *test_fn =
32 gcc_jit_context_new_function (ctxt, NULL,
33 GCC_JIT_FUNCTION_EXPORTED,
34 array_type,
35 "test_fn",
36 0, NULL,
37 0);
38 gcc_jit_lvalue *f =
39 gcc_jit_function_new_local (
40 test_fn,
41 NULL,
42 int_type, "f");
44 gcc_jit_block *block = gcc_jit_function_new_block (test_fn, NULL);
46 gcc_jit_block_end_with_return (
47 block, NULL,
48 gcc_jit_context_new_bitcast (ctxt, NULL,
49 gcc_jit_lvalue_as_rvalue (f),
50 array_type));
53 void
54 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
56 CHECK_VALUE (result, NULL);
58 /* Verify that the correct error message was emitted. */
59 CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
60 "bitcast with types of different sizes");