(root)/
gcc-13.2.0/
gcc/
testsuite/
gfortran.dg/
PR94327.c
       1  /* Test the fix for PR94327.  */
       2  
       3  #include <assert.h>
       4  #include <stdbool.h>
       5  #include <stdlib.h>
       6  
       7  #include <ISO_Fortran_binding.h>
       8  
       9  bool c_vrfy (const CFI_cdesc_t *restrict);
      10  
      11  char get_attr (const CFI_cdesc_t*restrict, bool);
      12  
      13  bool
      14  c_vrfy (const CFI_cdesc_t *restrict auxp)
      15  {
      16    CFI_index_t i, lb, ub, ex;
      17    int *ip = NULL;
      18  
      19    assert (auxp);
      20    assert (auxp->base_addr);
      21    lb = auxp->dim[0].lower_bound;
      22    ex = auxp->dim[0].extent;
      23    ub = ex + lb - 1;
      24    ip = (int*)auxp->base_addr;
      25    for (i=0; i<ex; i++)
      26      if (*ip++ != i+1)
      27        return false;
      28    for (i=lb; i<ub+1; i++)
      29      {
      30        ip = (int*)CFI_address(auxp, &i);
      31        if (*ip != i-lb+1)
      32  	return false;
      33      }
      34    return true;
      35  }
      36  
      37  char
      38  get_attr (const CFI_cdesc_t *restrict auxp, bool alloc)
      39  {
      40    char attr;
      41    
      42    assert (auxp);
      43    assert (auxp->elem_len == 4);
      44    assert (auxp->rank == 1);
      45    assert (auxp->type == CFI_type_int);
      46    attr = '\0';
      47    switch (auxp->attribute)
      48      {
      49      case CFI_attribute_pointer:
      50        if (alloc && !c_vrfy (auxp))
      51  	break;
      52        attr = 'p';
      53        break;
      54      case CFI_attribute_allocatable:
      55        if (alloc && !c_vrfy (auxp))
      56  	break;
      57        attr = 'a';
      58        break;
      59      case CFI_attribute_other:
      60        assert (alloc);
      61        if (!c_vrfy (auxp))
      62  	break;
      63        attr = 'o';
      64        break;
      65      default:
      66        break;
      67      }
      68    return attr;
      69  }
      70