summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_16.c
blob: 915b6e7d568e21fd2b6b2bdba8c1cfa77c143bcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* Test the fix for PR92142. */

#include <ISO_Fortran_binding.h>

#include <stdlib.h>

int c_setpointer(CFI_cdesc_t *);

int c_setpointer(CFI_cdesc_t *ip)
{
  CFI_cdesc_t *yp = NULL;
  void *auxp = ip->base_addr;
  int ierr;
  int status;

  /* Setting up the pointer */
  ierr = 1;
  yp = malloc(sizeof(*ip));
  if (yp == NULL) return ierr;
  status = CFI_establish(yp, NULL, CFI_attribute_pointer, ip->type, ip->elem_len, ip->rank, NULL);
  if (status != CFI_SUCCESS) return ierr;
  if (yp->attribute != CFI_attribute_pointer) return ierr;
  /* Set the pointer to ip */
  ierr = 2;
  status = CFI_setpointer(yp, ip, NULL);
  if (status != CFI_SUCCESS) return ierr;
  if (yp->attribute != CFI_attribute_pointer) return ierr;
  /* Set the pointer to NULL */
  ierr = 3;
  status = CFI_setpointer(yp, NULL, NULL);
  if (status != CFI_SUCCESS) return ierr;
  if (yp->attribute != CFI_attribute_pointer) return ierr;
  /* "Set" the ip variable to yp (should not be possible) */
  ierr = 4;
  status = CFI_setpointer(ip, yp, NULL);
  if (status != CFI_INVALID_ATTRIBUTE) return ierr;
  if (ip->attribute != CFI_attribute_other) return ierr;
  if (ip->base_addr != auxp) return ierr;
  return 0;
}