c++: prvalue of array type [PR111286]
[official-gcc.git] / gcc / testsuite / jit.dg / test-long-names.c
blob8f4aa7e7026f0bd3495041d3cda0421a9889975e
1 /* Test of using the API with very long names. */
3 #include <stdlib.h>
4 #include <stdio.h>
6 #include "libgccjit.h"
8 #include "harness.h"
10 /* 65KB */
11 #define NAME_LENGTH (65 * 1024)
13 static struct long_names
15 char struct_name[NAME_LENGTH];
16 char fn_name[NAME_LENGTH];
17 char local_name[NAME_LENGTH];
18 char block_name[NAME_LENGTH];
19 } long_names;
21 static void
22 populate_name (const char *prefix, char *buffer)
24 int i;
26 /* Begin with the given prefix: */
27 sprintf (buffer, "%s", prefix);
29 /* Populate the rest of the buffer with 0123456789 repeatedly: */
30 for (i = strlen (prefix); i < NAME_LENGTH - 1; i++)
31 buffer[i] = '0' + (i % 10);
33 /* NIL-terminate the buffer: */
34 buffer[NAME_LENGTH - 1] = '\0';
37 static void
38 populate_names (void)
40 populate_name ("struct_", long_names.struct_name);
41 populate_name ("test_fn_", long_names.fn_name);
42 populate_name ("local_", long_names.local_name);
43 populate_name ("block_", long_names.block_name);
46 void
47 create_code (gcc_jit_context *ctxt, void *user_data)
49 /* Where "ETC" is a very long suffix, let's try to inject the
50 equivalent of:
52 struct struct_ETC;
54 int
55 test_fn_ETC ()
57 int local_ETC;
58 local_ETC = 42;
59 return local_ETC;
62 to verify that the API copes with such long names. */
64 populate_names ();
66 gcc_jit_type *int_type =
67 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
69 /* We don't yet use this struct. */
70 (void)gcc_jit_context_new_opaque_struct (ctxt, NULL,
71 long_names.struct_name);
73 gcc_jit_function *test_fn =
74 gcc_jit_context_new_function (ctxt, NULL,
75 GCC_JIT_FUNCTION_EXPORTED,
76 int_type,
77 long_names.fn_name,
78 0, NULL,
79 0);
80 gcc_jit_lvalue *local =
81 gcc_jit_function_new_local (test_fn,
82 NULL,
83 int_type,
84 long_names.local_name);
86 gcc_jit_block *block =
87 gcc_jit_function_new_block (test_fn, long_names.block_name);
89 gcc_jit_block_add_assignment (
90 block,
91 NULL,
92 local,
93 gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 42));
95 gcc_jit_block_end_with_return (
96 block, NULL,
97 gcc_jit_lvalue_as_rvalue (local));
100 void
101 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
103 CHECK_NON_NULL (result);
105 typedef int (*my_fn_type) (void);
106 CHECK_NON_NULL (result);
107 my_fn_type my_fn =
108 (my_fn_type)gcc_jit_result_get_code (result, long_names.fn_name);
109 CHECK_NON_NULL (my_fn);
110 int val = my_fn ();
111 CHECK_VALUE (val, 42);