(root)/
gcc-13.2.0/
gcc/
testsuite/
jit.dg/
test-error-ctor-array-wrong-obj.c
       1  /*
       2  
       3    Test that the proper error is triggered when we build a ctor
       4    for an array type, but has the type wrong on an element.
       5  
       6  */
       7  
       8  #include <stdlib.h>
       9  #include <stdio.h>
      10  
      11  #include "libgccjit.h"
      12  #include "harness.h"
      13  
      14  void
      15  create_code (gcc_jit_context *ctxt, void *user_data)
      16  {
      17    gcc_jit_type *int_type = gcc_jit_context_get_type (ctxt,
      18      GCC_JIT_TYPE_INT);
      19    gcc_jit_type *float_type = gcc_jit_context_get_type (ctxt,
      20      GCC_JIT_TYPE_FLOAT);
      21  
      22    gcc_jit_type *arr_type =
      23      gcc_jit_context_new_array_type (ctxt, 0, int_type, 10);
      24  
      25    gcc_jit_rvalue *frv = gcc_jit_context_new_rvalue_from_double (ctxt,
      26  								float_type,
      27  								12);
      28  
      29    gcc_jit_rvalue *ctor = gcc_jit_context_new_array_constructor
      30      (ctxt, 0,
      31       arr_type,
      32       1,
      33       &frv);
      34  
      35    CHECK_VALUE (ctor, NULL);
      36  }
      37  
      38  void
      39  verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
      40  {
      41    /* Ensure that the bad API usage prevents the API giving a bogus
      42       result back.  */
      43    CHECK_VALUE (result, NULL);
      44  
      45    /* Verify that the correct error message was emitted. */
      46    CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
      47  		      "gcc_jit_context_new_array_constructor: array element "
      48  		      "value types differ from types in 'values' (element "
      49  		      "type: int)('values' type: float)");
      50    CHECK_STRING_VALUE (gcc_jit_context_get_last_error (ctxt),
      51  		      "gcc_jit_context_new_array_constructor: array element "
      52  		      "value types differ from types in 'values' (element "
      53  		      "type: int)('values' type: float)");
      54  }