(root)/
gcc-13.2.0/
gcc/
testsuite/
jit.dg/
test-long-string-literal.c
       1  #include <stdlib.h>
       2  #include <stdio.h>
       3  #include <string.h>
       4  #include <assert.h>
       5  
       6  #include "libgccjit.h"
       7  
       8  #include "harness.h"
       9  
      10  const char very_long_string[] =
      11    "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc"
      12    "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc"
      13    "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc"
      14    "abcabcabcabcabcabcabcabcabcabca";
      15  
      16  void
      17  create_code (gcc_jit_context *ctxt, void *user_data)
      18  {
      19    /* Build the test_fn.  */
      20    gcc_jit_function *f =
      21      gcc_jit_context_new_function (
      22        ctxt, NULL,
      23        GCC_JIT_FUNCTION_EXPORTED,
      24        gcc_jit_context_get_type(ctxt,
      25  			       GCC_JIT_TYPE_CONST_CHAR_PTR),
      26  				"test_long_string_literal",
      27  				0, NULL, 0);
      28    gcc_jit_block *blk =
      29      gcc_jit_function_new_block (f, "init_block");
      30  
      31    /* very_long_string is longer than 200 characters to specifically
      32       check that the previous limitation no longer apply.  */
      33  
      34    assert (sizeof (very_long_string) > 200);
      35    gcc_jit_rvalue *res =
      36      gcc_jit_context_new_string_literal (ctxt, very_long_string);
      37  
      38    gcc_jit_block_end_with_return (blk, NULL, res);
      39  }
      40  
      41  void
      42  verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
      43  {
      44    typedef const char *(*fn_type) (void);
      45    CHECK_NON_NULL (result);
      46    fn_type test_long_string_literal =
      47      (fn_type)gcc_jit_result_get_code (result, "test_long_string_literal");
      48    CHECK_NON_NULL (test_long_string_literal);
      49  
      50    /* Call the JIT-generated function.  */
      51    const char *str = test_long_string_literal ();
      52    CHECK_NON_NULL (str);
      53    CHECK_VALUE (strcmp (str, very_long_string), 0);
      54  }