Skip to content

Commit c7dc57c

Browse files
wanbinchen-hncbryanpkc
authored andcommitted
Fix regression about struct components passing for assume-shape formal arguments.
1 parent 7381c9c commit c7dc57c

File tree

4 files changed

+120
-2
lines changed

4 files changed

+120
-2
lines changed

test/f90_correct/inc/bound17.mk

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
$(TEST): run
8+
9+
build: $(SRC)/$(TEST).f90
10+
-$(RM) $(TEST).$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.*
11+
@echo ------------------------------------ building test $@
12+
-$(FC) -c $(FFLAGS) $(LDFLAGS) $(SRC)/$(TEST).f90 -o $(TEST).$(OBJX)
13+
-$(FC) $(FFLAGS) $(LDFLAGS) $(TEST).$(OBJX) $(LIBS) -o $(TEST).$(EXESUFFIX)
14+
15+
run:
16+
@echo ------------------------------------ executing test $(TEST)
17+
$(TEST).$(EXESUFFIX)
18+
19+
verify: ;

test/f90_correct/lit/bound17.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: 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/bound17.f90

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
! Test for LBOUND and UBOUND of assumed-shape formal when the corresponding
7+
! acutal is a struct component.
8+
9+
program test
10+
implicit none
11+
type my_type
12+
integer :: x(2,3,4)
13+
integer, allocatable :: x_alloc(:, :, :)
14+
integer, pointer :: x_ptr(:, :, :)
15+
end type
16+
type(my_type) :: obj
17+
integer, allocatable :: arr_res(:)
18+
character(len=:), allocatable :: char_res
19+
integer :: i
20+
21+
allocate(obj%x_alloc(2:3, 3:5, 4:7))
22+
allocate(obj%x_ptr(2:3, 3:5, 4:7))
23+
24+
arr_res = array_test_specified_lb(1, 0, -1, obj%x)
25+
if (size(arr_res) /= 8 .or. any(arr_res /= 1)) STOP 1
26+
arr_res = array_test_specified_lb(2, 1, 0, obj%x(2:, 3:, 2:))
27+
if (size(arr_res) /= 4 .or. any(arr_res /= 1)) STOP 2
28+
arr_res = array_test_missing_lb(obj%x_alloc)
29+
if (size(arr_res) /= 3 .or. any(arr_res /= 2)) STOP 3
30+
arr_res = array_test_specified_lb(1, 0, -1, obj%x_alloc)
31+
if (size(arr_res) /= 8 .or. any(arr_res /= 1)) STOP 4
32+
arr_res = array_test_missing_lb(obj%x_ptr)
33+
if (size(arr_res) /= 3 .or. any(arr_res /= 2)) STOP 5
34+
35+
char_res = char_test_specified_lb(1, 0, -1, obj%x)
36+
if (len(char_res) /= 8 .or. char_res /= 'aaaaaaaa') STOP 6
37+
char_res = char_test_specified_lb(2, 1, 0, obj%x(2:, 3:, 2:))
38+
if (len(char_res) /= 4 .or. char_res /= 'aaaa') STOP 7
39+
char_res = char_test_missing_lb(obj%x_alloc)
40+
if (len(char_res) /= 3 .or. char_res /= 'bbb') STOP 8
41+
char_res = char_test_specified_lb(1, 0, -1, obj%x_alloc)
42+
if (len(char_res) /= 8 .or. char_res /= 'aaaaaaaa') STOP 9
43+
char_res = char_test_missing_lb(obj%x_ptr)
44+
if (len(char_res) /= 3 .or. char_res /= 'bbb') STOP 10
45+
46+
arr_res = test_noncnst_dim(1, 0, -1, obj%x, 1, 2, 3)
47+
if (size(arr_res) /= 8 .or. any(arr_res /= 1)) STOP 11
48+
49+
print *, "PASS"
50+
contains
51+
function array_test_specified_lb(l1, l2, l3, a) result(res)
52+
integer :: l1, l2, l3
53+
integer :: a(l1:, l2:, l3:)
54+
integer :: res(1:ubound(a, 1) * ubound(a, 2) * ubound(a, 3))
55+
res = 1
56+
end function
57+
58+
function array_test_missing_lb(a) result(res)
59+
integer :: a(:, :, :)
60+
integer :: res(1:lbound(a, 1) + lbound(a, 2) + lbound(a, 3))
61+
res = 2
62+
end function
63+
64+
function char_test_specified_lb(l1, l2, l3, a) result(res)
65+
integer :: l1, l2, l3
66+
integer :: a(l1:, l2:, l3:)
67+
character(len=ubound(a, 1) * ubound(a, 2) * ubound(a, 3)) :: res
68+
res = repeat('a', ubound(a, 1) * ubound(a, 2) * ubound(a, 3))
69+
end function
70+
71+
function char_test_missing_lb(a) result(res)
72+
integer :: a(:, :, :)
73+
character(len=lbound(a, 1) + lbound(a, 2) + lbound(a, 3)) :: res
74+
res = repeat('b', lbound(a, 1) + lbound(a, 2) + lbound(a, 3))
75+
end function
76+
77+
function test_noncnst_dim(l1, l2, l3, a, d1, d2, d3) result(res)
78+
integer :: l1, l2, l3
79+
integer :: a(l1:, l2:, l3:)
80+
integer :: d1, d2, d3
81+
integer :: res(1:ubound(a, d1) * ubound(a, d2) * ubound(a, d3))
82+
res = 1
83+
end function
84+
end program

tools/flang1/flang1exe/func.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7706,7 +7706,10 @@ rewrite_lbound_ubound(int func_ast, int actual, int nextstd)
77067706
(POINTERG(actual_sptr) || ALLOCG(actual_sptr))) {
77077707
/* The whole array actual_sptr corresponding to an assumed-shape
77087708
* formal cannot be assumed-rank. */
7709-
extent = get_extent(SDSCG(actual_sptr), i - 1);
7709+
int subs[1];
7710+
int desc = find_descriptor_ast(actual_sptr, actual);
7711+
subs[0] = mk_isz_cval(get_global_extent_index(i - 1), astb.bnd.dtype);
7712+
extent = mk_subscr(desc, subs, 1, astb.bnd.dtype);
77107713
} else {
77117714
extent = extent_of_shape(A_SHAPEG(actual), i - 1);
77127715
}
@@ -7902,7 +7905,10 @@ rewrite_lbound_ubound(int func_ast, int actual, int nextstd)
79027905
(POINTERG(actual_sptr) || ALLOCG(actual_sptr))) {
79037906
/* The whole array actual_sptr corresponding to an assumed-shape
79047907
* formal cannot be assumed-rank. */
7905-
extent = get_extent(SDSCG(actual_sptr), i);
7908+
int subs[1];
7909+
int desc = find_descriptor_ast(actual_sptr, actual);
7910+
subs[0] = mk_isz_cval(get_global_extent_index(i - 1), astb.bnd.dtype);
7911+
extent = mk_subscr(desc, subs, 1, astb.bnd.dtype);
79067912
} else {
79077913
extent = extent_of_shape(A_SHAPEG(actual), i);
79087914
}

0 commit comments

Comments
 (0)