(root)/
gcc-13.2.0/
gcc/
testsuite/
jit.dg/
test-error-gcc_jit_lvalue_get_address-bitfield.c
       1  #include <stdlib.h>
       2  #include <stdio.h>
       3  
       4  #include "libgccjit.h"
       5  
       6  #include "harness.h"
       7  
       8  /* Try to dereference a bit-field.  */
       9  
      10  void
      11  create_code (gcc_jit_context *ctxt, void *user_data)
      12  {
      13    /* Let's try to inject the equivalent of:
      14  
      15       struct bit_foo
      16       {
      17         int i:3;
      18         int j:3;
      19       };
      20  
      21       struct bit_foo f;
      22       &(f.j)
      23    */
      24    gcc_jit_type *int_type =
      25      gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
      26    gcc_jit_field *i =
      27      gcc_jit_context_new_bitfield (ctxt,
      28  				  NULL,
      29  				  int_type,
      30  				  3,
      31  				  "i");
      32    gcc_jit_field *j =
      33      gcc_jit_context_new_bitfield (ctxt,
      34  				  NULL,
      35  				  int_type,
      36  				  3,
      37  				  "j");
      38    gcc_jit_field *fields[] = {i, j};
      39    gcc_jit_type *struct_type =
      40      gcc_jit_struct_as_type (
      41        gcc_jit_context_new_struct_type (ctxt, NULL, "bit_foo", 2, fields));
      42  
      43    gcc_jit_lvalue *f_struct =
      44      gcc_jit_context_new_global (ctxt,
      45  				NULL,
      46  				GCC_JIT_GLOBAL_INTERNAL,
      47  				struct_type,
      48  				"f");
      49  
      50    gcc_jit_lvalue_get_address (
      51      gcc_jit_lvalue_access_field (
      52        f_struct,
      53        NULL,
      54        j),
      55      NULL);
      56  }
      57  
      58  void
      59  verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
      60  {
      61    CHECK_VALUE (result, NULL);
      62  
      63    /* Verify that the correct error message was emitted.  */
      64    CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
      65  		      "cannot take address of bit-field");
      66  }