(root)/
gcc-13.2.0/
gcc/
testsuite/
gfortran.dg/
PR100915.c
       1  /* Test the fix for PR100915 */
       2  
       3  #include <assert.h>
       4  #include <stdbool.h>
       5  #include <stdio.h>
       6  
       7  #include <ISO_Fortran_binding.h>
       8  
       9  #define _CFI_type_mask 0xFF
      10  #define _CFI_type_kind_shift 8
      11  
      12  #define _CFI_decode_type(NAME) (signed char)((NAME) & CFI_type_mask)
      13  #define _CFI_decode_kind(NAME) (signed char)(((NAME) >> CFI_type_kind_shift) & CFI_type_mask)
      14  
      15  #define _CFI_encode_type(TYPE, KIND) (int16_t)\
      16  ((((KIND) & CFI_type_mask) << CFI_type_kind_shift)\
      17   | ((TYPE) & CFI_type_mask))
      18  
      19  #define N 11
      20  #define M 7
      21  
      22  typedef int(*c_funptr)(int);
      23  
      24  bool c_vrfy_c_funptr (const CFI_cdesc_t *restrict);
      25  
      26  void check_fn (const CFI_cdesc_t*restrict, const CFI_type_t, const signed char, const size_t, const size_t);
      27  
      28  bool
      29  c_vrfy_c_funptr (const CFI_cdesc_t *restrict auxp)
      30  {
      31    CFI_index_t i, lb, ub, ex;
      32    size_t sz;
      33    c_funptr *ip = NULL;
      34  
      35    assert (auxp);
      36    assert (auxp->base_addr);
      37    assert (auxp->elem_len>0);
      38    lb = auxp->dim[0].lower_bound;
      39    ex = auxp->dim[0].extent;
      40    assert (ex==11);
      41    sz = (size_t)auxp->elem_len / sizeof (c_funptr);
      42    assert (sz==1);
      43    ub = ex + lb - 1;
      44    ip = (c_funptr*)auxp->base_addr;
      45    for (i=0; i<ex; i++, ip+=sz)
      46      if ((**ip)((int)(i)) != 2*(int)(i))
      47        return false;
      48    for (i=lb; i<ub+1; i++)
      49      {
      50        ip = (c_funptr*)CFI_address(auxp, &i);
      51        if ((**ip)((int)(i-lb)) != 2*(int)(i-lb))
      52  	return false;
      53      }
      54    return true;
      55  }
      56  
      57  void
      58  check_fn (const CFI_cdesc_t *restrict auxp, const CFI_type_t type, const signed char kind, const size_t elem_len, const size_t nelem)
      59  {
      60    signed char ityp, iknd;
      61  
      62    assert (auxp);
      63    assert (auxp->elem_len==elem_len*nelem);
      64    assert (auxp->rank==1);
      65    assert (auxp->dim[0].sm>0);
      66    assert ((size_t)auxp->dim[0].sm==elem_len*nelem);
      67    /*  */
      68    assert (auxp->type==type);
      69    ityp = _CFI_decode_type(auxp->type);
      70    assert (ityp == CFI_type_cfunptr);
      71    iknd = _CFI_decode_kind(auxp->type);
      72    assert (_CFI_decode_type(type)==ityp);
      73    assert (kind==iknd);
      74    assert (c_vrfy_c_funptr (auxp));
      75    return;
      76  }
      77  
      78  // Local Variables:
      79  // mode: C
      80  // End: