* gcc-interface/trans.c (node_has_volatile_full_access) <N_Identifier>:
[official-gcc.git] / gcc / testsuite / jit.dg / test-string-literal.c
blob097830d05cb6109195897809fc1c176154565d55
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
5 #include "libgccjit.h"
7 #include "harness.h"
9 void
10 create_code (gcc_jit_context *ctxt, void *user_data)
12 /* Let's try to inject the equivalent of:
14 const char *
15 test_string_literal (void)
17 return "hello world";
20 gcc_jit_type *const_char_ptr_type =
21 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_CONST_CHAR_PTR);
23 /* Build the test_fn. */
24 gcc_jit_function *test_fn =
25 gcc_jit_context_new_function (ctxt, NULL,
26 GCC_JIT_FUNCTION_EXPORTED,
27 const_char_ptr_type,
28 "test_string_literal",
29 0, NULL,
30 0);
31 gcc_jit_block *block = gcc_jit_function_new_block (test_fn, NULL);
33 gcc_jit_block_end_with_return (
34 block, NULL,
35 gcc_jit_context_new_string_literal (ctxt, "hello world"));
38 void
39 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
41 typedef const char *(*fn_type) (void);
42 CHECK_NON_NULL (result);
43 fn_type test_string_literal =
44 (fn_type)gcc_jit_result_get_code (result, "test_string_literal");
45 CHECK_NON_NULL (test_string_literal);
47 /* Call the JIT-generated function. */
48 const char *str = test_string_literal ();
49 CHECK_NON_NULL (str);
50 CHECK_VALUE (strcmp (str, "hello world"), 0);