Skip to content

Commit 4df6dac

Browse files
shivaramaaraopawosm-arm
authored andcommitted
[flang1] Fix the issue with contiguous dummy argument arrays (#1426)
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.
1 parent 2693fba commit 4df6dac

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

test/f90_correct/inc/cont01.mk

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
build:
6+
@echo ------------------------------------- building test $(TEST)
7+
$(FC) $(FFLAGS) $(SRC)/$(TEST).f90 $(SRC)/c_$(TEST).c $(SRC)/check.c -o $(TEST).$(EXESUFFIX)
8+
9+
run:
10+
@echo ------------------------------------ executing test $(TEST)
11+
./$(TEST).$(EXESUFFIX)
12+
13+
verify: ;

test/f90_correct/lit/cont01.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3+
# See https://llvm.org/LICENSE.txt for license information.
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
# Shared lit script for each tests. Run bash commands that run tests with make.
7+
8+
# RUN: env KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%/s MAKE_FILE_DIR=%/S/.. bash %/S/runmake | tee %/t
9+
# RUN: cat %t | FileCheck %S/runmake

test/f90_correct/src/c_cont01.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3+
* See https://llvm.org/LICENSE.txt for license information.
4+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
*/
6+
7+
int pass_contiguous_array_c(const void *data, int m, int n, int *res) {
8+
const int *data_i = (const int *)data;
9+
for(int i = 0; i < m; i++) {
10+
for(int j = 0; j < n; j++) {
11+
res[i * n + j ] = data_i[i * n + j];
12+
}
13+
}
14+
return 0;
15+
}

test/f90_correct/src/cont01.f90

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
!** Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3+
!** See https://llvm.org/LICENSE.txt for license information.
4+
!** SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
!
6+
! testing if contiguous arrays passed as argument are really contiguous
7+
8+
program main
9+
integer, parameter :: m=6,n=4,h=2
10+
integer :: i,j
11+
12+
integer(kind=4), allocatable :: big_array(:, :)
13+
integer(kind=4) :: expected(n-h, m-h)
14+
integer(kind=4) :: res(n-h, m-h)
15+
allocate(big_array(n, m))
16+
do i=1,n
17+
do j=1,m
18+
big_array(i,j) = i
19+
enddo
20+
enddo
21+
expected = big_array(1:n-h,1:m-h)
22+
call pass_contiguous_array(big_array(1:n-h,1:m-h), m, n, h, res)
23+
call check(res,expected,(n-h)*(m-h));
24+
25+
contains
26+
subroutine pass_contiguous_array(arr, m, n, h, res)
27+
use iso_c_binding
28+
implicit none
29+
integer(kind=4), target, contiguous, intent(in) :: arr(:,:)
30+
integer(kind=4), target, intent(inout) :: res(n-h,m-h)
31+
integer, intent(in) :: m, n, h
32+
integer :: err
33+
34+
interface
35+
function pass_contiguous_array_c(data, m, n,res) result(error_code) BIND(c)
36+
import c_int, c_float, c_double, c_ptr
37+
integer(c_int), VALUE, intent(in) :: m
38+
integer(c_int), VALUE, intent(in) :: n
39+
type(c_ptr), VALUE, intent(in) :: data
40+
type(c_ptr), VALUE, intent(in) :: res
41+
integer(c_int) :: error_code
42+
end function pass_contiguous_array_c
43+
end interface
44+
45+
err = pass_contiguous_array_c(c_loc(arr), m-h, n-h,c_loc(res))
46+
end subroutine pass_contiguous_array
47+
end program

tools/flang1/flang1exe/rest.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,6 +2385,8 @@ is_seq_dummy(int entry, int arr, int loc)
23852385
dummy_sptr = aux.dpdsc_base[dscptr + loc];
23862386
if (SEQG(dummy_sptr))
23872387
return TRUE;
2388+
if (CONTIGATTRG(dummy_sptr))
2389+
return TRUE;
23882390
if (ASSUMSHPG(dummy_sptr))
23892391
return FALSE;
23902392
return TRUE;

0 commit comments

Comments
 (0)