<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/64899>64899</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [flang] Incorrect value of lower_bound in C descriptor for nonallocatable nonpointer object
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          kkwli
      </td>
    </tr>
</table>

<pre>
    The value of `lower_bound` is incorrect for nonallocatable nonpointer object.

## C source
```c
#include <stdio.h>
#include "ISO_Fortran_binding.h"

void getbounds(CFI_cdesc_t *p)
{
 printf("%s: attribute=", __func__);
  switch (p->attribute) {
  case CFI_attribute_pointer:
    printf("pointer\n");
    break;
  case CFI_attribute_allocatable:
    printf("allocatable\n");
 break;
  default:
    printf("other\n");
  }
  for (int i=0; i<p->rank; i++) {
    printf("%s: dim[%d].lower_bound=%ld  extent=%ld sm=%ld\n", __func__,
           i, p->dim[i].lower_bound, p->dim[i].extent, p->dim[i].sm);
  }
}
```
## Fortran source
```fortran
interface
  subroutine foo(x) bind(c)
  real :: x(:)
  end
end interface
real :: z(7) 
call foo(z)
end

subroutine foo(x) bind(c)
  interface
 subroutine getbounds(p) bind(c)
    real :: p(:)
    end
  end interface
  real :: x(:)
  call getbounds(x)
end
```
## Output
```
getbounds: attribute=other
getbounds: dim[0].lower_bound=1  extent=7  sm=4
```
The value of `lower_bound` should be 0 according to the standard:
> For a C descriptor of a nonallocatable nonpointer object, the value of the `lower_bound` member of each element of the `dim` member of the descriptor is zero.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVc1uszoTvhqzGTUCOySwYJEmjdTVu_i-PTK2CT51bGSbtqdXf2QghCREfSNEBs94nmf-bOqcPGkhCpS-ovQQ0c43xhYfH19KRpXh_xb_bwR8UtUJMDWgTazMl7BlZTrN0SYG6UBqZqwVzENt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