Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The 'contiguous' attribute does not enforce an array passed to a subroutine to be contiguous #1426

Closed
pawosm-arm opened this issue Oct 18, 2023 · 0 comments
Assignees

Comments

@pawosm-arm
Copy link
Collaborator

pawosm-arm commented Oct 18, 2023

In a simple subroutine like that:

    subroutine print_array(arr, m, n, h)
        use iso_c_binding
        implicit none
        integer(kind=4), target, contiguous, intent(in) :: arr(:,:)
        integer, intent(in) :: m, n, h
        integer :: err

        interface
          function print_array_c(data, m, n) result(error_code) BIND(c)
            import c_int, c_float, c_double, c_ptr
            integer(c_int), VALUE, intent(in) :: m
            integer(c_int), VALUE, intent(in) :: n
            type(c_ptr),    VALUE, intent(in) :: data
            integer(c_int)                    :: error_code
          end function print_array_c
        end interface

        err = print_array_c(c_loc(arr), m-h, n-h)
    end subroutine print_array

The array passed as the first parameter is expected to be contiguous. When passing entire arrays, this works. But when a piece of array is passed, a new array of the sliced size is not being created, what is passed in the memory is still of the size of the original array, and from the sliced portion point of view, it is not contiguous, which is clearly visible in the called C code (it doesn't have to be C code, similar experiment using c_loc and transfer can be replicated in Fortran)

  integer(kind=4), allocatable :: big_array(:, :)
  ...
  allocate(big_array(n, m))
  ...
  call print_array(big_array(1:n-h,1:m-h), m, n, h)
int print_array_c(const void *data, int m, int n)
{
    const int *data_i = (const int *)data;
    for(int i = 0; i < m; i++)
    {
        for(int j = 0; j < n; j++)
            printf("%d ", data_i[i * n + j]);
        printf("\n");
    }
    return 0;
}
shivaramaarao added a commit that referenced this issue Nov 5, 2023
When array dummy arguments are marked as contiguous,compiler need to generate
and pass sequential copy of formal arguments.

This issue is fixed as part of this commit.
shivaramaarao added a commit that referenced this issue Nov 6, 2023
When array dummy arguments are marked as contiguous,compiler need to generate
and pass sequential copy of formal arguments.

This issue is fixed as part of this commit.
pawosm-arm pushed a commit that referenced this issue Nov 15, 2023
When array dummy arguments are marked as contiguous,compiler need to generate
and pass sequential copy of formal arguments.

This issue is fixed as part of this commit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants