Skip to content

Commit 3de1cba

Browse files
zhangruinanbryanpkc
authored andcommitted
[flang2] Fix bug in implied DO expression in a used module
The variables in a common block from a module will be copied into current scope when a USE exists. However, the dinit feature of those copied variables was removed when lowering symbols in flang1. This patch suppresses the transformation of those copied variables to the corresponding constant initialized in the common block, since we cannot get their initialization info anyway.
1 parent 39997ea commit 3de1cba

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
-$(CC) -c $(CFLAGS) $(SRC)/check.c -o check.$(OBJX)
14+
-$(FC) -c $(FFLAGS) $(LDFLAGS) $(SRC)/$(TEST).f90 -o $(TEST).$(OBJX)
15+
-$(FC) $(FFLAGS) $(LDFLAGS) $(TEST).$(OBJX) check.$(OBJX) $(LIBS) -o $(TEST).$(EXESUFFIX)
16+
17+
18+
run:
19+
@echo ------------------------------------ executing test $(TEST)
20+
$(TEST).$(EXESUFFIX)
21+
22+
verify: ;
23+
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
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
! Part of the LLVM Project, under the Apache License v2.0 with LLVM
2+
! 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 implied DO expression in module.
7+
!
8+
9+
module mod_impliedDo
10+
integer :: i
11+
character(*), parameter :: a = "Hello world!"
12+
character(*), parameter :: b1(2) = [(a(i:i+4),i=1,7,6)]
13+
end module
14+
15+
program p
16+
use mod_impliedDo
17+
character(5) :: c(2)
18+
c(1) = b1(1)
19+
c(2) = b1(2)
20+
call check(c, "Helloworld", 1)
21+
end program

tools/flang2/flang2exe/dinit.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5824,8 +5824,7 @@ eval_init_expr_item(CONST *cur_e)
58245824
}
58255825
if (PARAMG(cur_e->sptr) || (DOVARG(cur_e->sptr) && DINITG(cur_e->sptr)) ||
58265826
(CCSYMG(cur_e->sptr) && DINITG(cur_e->sptr))) {
5827-
if (!PARAMVALG(cur_e->sptr) && DTY(DTYPEG(cur_e->sptr)) == TY_CHAR
5828-
&& SCG(cur_e->sptr) == SC_STATIC) {
5827+
if (!PARAMVALG(cur_e->sptr) && DTY(DTYPEG(cur_e->sptr)) == TY_CHAR) {
58295828
new_e = get_static_str(cur_e->sptr);
58305829
break;
58315830
}
@@ -5834,6 +5833,15 @@ eval_init_expr_item(CONST *cur_e)
58345833
if (cur_e->mbr) {
58355834
new_e->sptr = cur_e->mbr;
58365835
}
5836+
break;
5837+
}
5838+
if (SCG(cur_e->sptr) == SC_CMBLK &&
5839+
FROMMODG(MIDNUMG(cur_e->sptr)) && MODCMNG(MIDNUMG(cur_e->sptr))) {
5840+
/* The dinit flag will be removed when lowering if the variable is from an
5841+
* external module. The branch deals with those variables from module
5842+
* commons to directly return the original variable.
5843+
*/
5844+
new_e = clone_init_const(cur_e, true);
58375845
}
58385846
break;
58395847
case AC_CONST:

0 commit comments

Comments
 (0)