Skip to content

Commit ac60021

Browse files
yaoliu-hncbryanpkc
authored andcommitted
Fix for regression introduced by PR #1036 (issue #1137).
When the entry returns adjustable length character without POINTER attribute, the field NEWARG of the return variable is not set which causes that the return variable in dummy arguments is not replaced, and the field CVLEN of the return variable also needs to be replaced.
1 parent 51688a5 commit ac60021

File tree

5 files changed

+180
-5
lines changed

5 files changed

+180
-5
lines changed

test/f90_correct/inc/en05.mk

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

test/f90_correct/lit/en05.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/en04.f90

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ function f5 ()
3737
e5 = (/1,2,3,4,5/)
3838
end function
3939

40+
function f6 (n)
41+
integer :: n
42+
character(n) :: f6, e6
43+
entry e6 (n)
44+
e6 = "hello1"
45+
end function
46+
47+
function f7 (n)
48+
integer :: n
49+
character(n), pointer :: f7, e7
50+
entry e7 (n)
51+
allocate(e7)
52+
e7 = "hello2"
53+
end function
54+
4055
program test
4156
interface
4257
function f1 ()
@@ -69,10 +84,27 @@ function f5 ()
6984
function e5 ()
7085
integer, dimension(:), pointer :: e5
7186
end function
87+
function f6 (n)
88+
integer :: n
89+
character(n) :: f6
90+
end function
91+
function e6 (n)
92+
integer :: n
93+
character(n) :: e6
94+
end function
95+
function f7 (n)
96+
integer :: n
97+
character(n), pointer :: f7
98+
end function
99+
function e7 (n)
100+
integer :: n
101+
character(n), pointer :: e7
102+
end function
72103
end interface
73104

74-
integer, parameter :: n = 10
105+
integer, parameter :: n = 14
75106
integer :: rslts(n), expect(n)
107+
character(6), pointer :: p
76108

77109
rslts = 0
78110
expect = 1
@@ -86,6 +118,18 @@ function e5 ()
86118
if (all(e4() == (/1,2,3,4/))) rslts(8) = 1
87119
if (all(f5() == (/1,2,3,4,5/))) rslts(9) = 1
88120
if (all(e5() == (/1,2,3,4,5/))) rslts(10) = 1
121+
if (len(f6(6)) == 6 .and. f6(6) == "hello1") rslts(11) = 1
122+
if (len(e6(6)) == 6 .and. e6(6) == "hello1") rslts(12) = 1
123+
p => f7(6)
124+
if (associated(p)) then
125+
if (len(p) == 6 .and. p == "hello2") rslts(13) = 1
126+
deallocate(p)
127+
endif
128+
p => e7(6)
129+
if (associated(p)) then
130+
if (len(p) == 6 .and. p == "hello2") rslts(14) = 1
131+
deallocate(p)
132+
endif
89133

90134
call check(rslts, expect, n)
91135
end program

test/f90_correct/src/en05.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 the fix for introduced error, in which the entry returns adjustable
7+
! length character.
8+
9+
function f1(n)
10+
integer :: n
11+
character(n) :: f1, e1
12+
f1 = "AB"
13+
return
14+
entry e1(n)
15+
e1 = "XYZ"
16+
end function
17+
18+
function f2(n)
19+
integer :: n
20+
character(n), pointer :: f2, e2
21+
allocate(f2)
22+
f2 = "AB"
23+
return
24+
entry e2(n)
25+
allocate(e2)
26+
e2 = "XYZ"
27+
end function
28+
29+
function f3(n)
30+
integer :: n
31+
character(n), dimension(2, 2) :: f3, e3
32+
f3 = "AB"
33+
return
34+
entry e3(n)
35+
e3 = "XYZ"
36+
end function
37+
38+
program p
39+
interface
40+
function f1(n)
41+
integer :: n
42+
character(n) :: f1
43+
end function
44+
function e1(n)
45+
integer :: n
46+
character(n) :: e1
47+
end function
48+
function f2(n)
49+
integer :: n
50+
character(n), pointer :: f2
51+
end function
52+
function e2(n)
53+
integer :: n
54+
character(n), pointer :: e2
55+
end function
56+
function f3(n)
57+
integer :: n
58+
character(n), dimension(2, 2) :: f3
59+
end function
60+
function e3(n)
61+
integer :: n
62+
character(n), dimension(2, 2) :: e3
63+
end function
64+
end interface
65+
character(:), pointer :: cp
66+
67+
if (len(f1(2)) /= 2 .or. f1(2) /= "AB") STOP 1
68+
if (len(e1(3)) /= 3 .or. e1(6) /= "XYZ") STOP 2
69+
70+
cp => f2(2)
71+
if (.not. associated(cp)) STOP 3
72+
if (len(cp) /= 2 .or. cp /= "AB") STOP 4
73+
deallocate(cp)
74+
75+
cp => e2(3)
76+
if (.not. associated(cp)) STOP 5
77+
if (len(cp) /= 3 .or. cp /= "XYZ") STOP 6
78+
deallocate(cp)
79+
80+
if (len(f3(2)) /= 2 .or. any(f3(2) /= "AB")) STOP 7
81+
if (len(e3(3)) /= 3 .or. any(e3(3) /= "XYZ")) STOP 8
82+
83+
print *, "PASS"
84+
end program

tools/flang1/flang1exe/lowersym.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,21 +1239,32 @@ replace_fval_in_params(SPTR entry, SPTR entrysame)
12391239
SPTR fval, fvalsame, newdsc, newdscsame, newarg, newargsame;
12401240
int params, narg, i;
12411241

1242+
narg = PARAMCTG(entry);
1243+
if (narg == 0)
1244+
return;
1245+
params = DPDSCG(entry);
12421246
fval = FVALG(entry);
12431247
fvalsame = FVALG(entrysame);
12441248
newdsc = NEWDSCG(fval);
12451249
newarg = NEWARGG(fval);
1250+
/* If the return variable is an adjustable length character without POINTER
1251+
* attribute, its NEWARG keeps SPTR_NULL(see init_newargs in bblock.c), and
1252+
* itself will be put into dummy parameters(see newargs_for_entry in
1253+
* dpm_out.c), so we match and replace the return variable directly.
1254+
*/
1255+
if (newarg == SPTR_NULL)
1256+
newarg = fval;
12461257
newdscsame = NEWDSCG(fvalsame);
12471258
newargsame = NEWARGG(fvalsame);
1248-
params = DPDSCG(entry);
1249-
narg = PARAMCTG(entry);
1259+
if (newargsame == SPTR_NULL)
1260+
newargsame = fvalsame;
12501261
for (i = 0; i < narg; i++) {
12511262
int arg = aux.dpdsc_base[params + i];
1252-
if (arg != 0 && arg == newarg) {
1263+
if (arg != SPTR_NULL && arg == newarg) {
12531264
aux.dpdsc_base[params + i] = newargsame;
12541265
continue;
12551266
}
1256-
if (arg != 0 && arg == newdsc) {
1267+
if (arg != SPTR_NULL && arg == newdsc) {
12571268
aux.dpdsc_base[params + i] = newdscsame;
12581269
continue;
12591270
}
@@ -1318,6 +1329,11 @@ replace_fval_in_ast(SPTR fval, SPTR fvalsame)
13181329
var_same = SDSCG(fvalsame);
13191330
add_replace_map(var, var_same);
13201331
replace_sptr_in_ast(var);
1332+
1333+
var = CVLENG(fval);
1334+
var_same = CVLENG(fvalsame);
1335+
add_replace_map(var, var_same);
1336+
replace_sptr_in_ast(var);
13211337
}
13221338

13231339
extern int pghpf_type_sptr;

0 commit comments

Comments
 (0)