(root)/
gcc-13.2.0/
gcc/
testsuite/
jit.dg/
test-error-ctor-struct-too-big.c
       1  /*
       2  
       3    Test that the proper error is triggered when we build a ctor
       4    for an struct type, but have too many fields and values.
       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  
      20    gcc_jit_field *b1 = gcc_jit_context_new_field (ctxt,
      21  						 0,
      22  						 int_type,
      23  						 "a");
      24    gcc_jit_field *b2 = gcc_jit_context_new_field (ctxt,
      25  						 0,
      26  						 int_type,
      27  						 "b");
      28    gcc_jit_field *b3 = gcc_jit_context_new_field (ctxt,
      29  						 0,
      30  						 int_type,
      31  						 "c");
      32    gcc_jit_field *fields_b[] = {b1, b2, b3};
      33  
      34    gcc_jit_type *struct_bar_type =
      35      gcc_jit_struct_as_type (
      36        gcc_jit_context_new_struct_type (ctxt,
      37  				       0,
      38  				       "bar",
      39  				       3,
      40  				       fields_b));
      41  
      42    gcc_jit_field *fields_ctor[] = {b1, b2, b3, b3};
      43    gcc_jit_rvalue *values[] = {0,0,0,0};
      44  
      45    gcc_jit_rvalue *ctor = gcc_jit_context_new_struct_constructor
      46      (ctxt, 0,
      47       struct_bar_type,
      48       4,
      49       fields_ctor,
      50       values);
      51  
      52    CHECK_VALUE (ctor, NULL);
      53  }
      54  
      55  void
      56  verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
      57  {
      58    /* Ensure that the bad API usage prevents the API giving a bogus
      59       result back.  */
      60    CHECK_VALUE (result, NULL);
      61  
      62    /* Verify that the correct error message was emitted. */
      63    CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
      64  		      "gcc_jit_context_new_struct_constructor: more values in "
      65  		      "constructor (n=4) than fields in target struct "
      66  		      "bar (n=3)");
      67    CHECK_STRING_VALUE (gcc_jit_context_get_last_error (ctxt),
      68  		      "gcc_jit_context_new_struct_constructor: more values in "
      69  		      "constructor (n=4) than fields in target struct "
      70  		      "bar (n=3)");
      71  }