Skip to content

Commit

Permalink
[flang1] Fix handling of LBOUND/UBOUND in type specification
Browse files Browse the repository at this point in the history
An issue occurs when LBOUND/UBOUND appears in the type specification
of a function result and the DIM argument is missing.

The root cause of this issue is that LBOUND/UBOUND is converted to
runtime call in semantic phase, which is too early for type-spec of
a function result. On the calling side of the function, we have no
way of knowing whether LBOUND/UBOUND exists or its reference to the
function's dummy arguments.

We fix the issue by delaying the conversion to the tranform phase.
In particular, we perform the conversion in dummy-actual argument
replacement if the array argument of LBOUND/UBOUND is an assumed-shape
array dummy.

In addition, we fix an ICE that occurs when LBOUND/UBOUND appears in
subscript expressions in type-spec, fix the link error that occurs
when both DIM and KIND arguments are present, fix an issue with LBOUND
on the last dimension of an assumed-size array, and add support for
LBOUND/UBOUND on an assumed-rank array.
  • Loading branch information
wanbinchen-hnc authored and bryanpkc committed Nov 14, 2023
1 parent 0326f92 commit 2693fba
Show file tree
Hide file tree
Showing 60 changed files with 2,054 additions and 630 deletions.
19 changes: 19 additions & 0 deletions test/f90_correct/inc/bound1.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#

$(TEST): run

build: $(SRC)/$(TEST).f90
-$(RM) $(TEST).$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.*
@echo ------------------------------------ building test $@
-$(FC) -c $(FFLAGS) $(LDFLAGS) $(SRC)/$(TEST).f90 -o $(TEST).$(OBJX)
-$(FC) $(FFLAGS) $(LDFLAGS) $(TEST).$(OBJX) $(LIBS) -o $(TEST).$(EXESUFFIX)

run:
@echo ------------------------------------ executing test $(TEST)
$(TEST).$(EXESUFFIX)

verify: ;
14 changes: 14 additions & 0 deletions test/f90_correct/inc/bound10.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

build: $(SRC)/$(TEST).f90
@echo ------------------------------------ building test $(TEST)
-$(FC) -c $(SRC)/$(TEST).f90 > $(TEST).rslt 2>&1

run:
@echo ------------------------------------ nothing to run for test $(TEST)

verify: $(TEST).rslt
@echo ------------------------------------ verifying test $(TEST)
$(COMP_CHECK) $(SRC)/$(TEST).f90 $(TEST).rslt $(FC)
19 changes: 19 additions & 0 deletions test/f90_correct/inc/bound11.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#

$(TEST): run

build: $(SRC)/$(TEST).f90
-$(RM) $(TEST).$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.*
@echo ------------------------------------ building test $@
-$(FC) -c $(FFLAGS) $(LDFLAGS) $(SRC)/$(TEST).f90 -o $(TEST).$(OBJX)
-$(FC) $(FFLAGS) $(LDFLAGS) $(TEST).$(OBJX) $(LIBS) -o $(TEST).$(EXESUFFIX)

run:
@echo ------------------------------------ executing test $(TEST)
$(TEST).$(EXESUFFIX)

verify: ;
19 changes: 19 additions & 0 deletions test/f90_correct/inc/bound12.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#

$(TEST): run

build: $(SRC)/$(TEST).f90
-$(RM) $(TEST).$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.*
@echo ------------------------------------ building test $@
-$(FC) -c $(FFLAGS) $(LDFLAGS) $(SRC)/$(TEST).f90 -o $(TEST).$(OBJX)
-$(FC) $(FFLAGS) $(LDFLAGS) $(TEST).$(OBJX) $(LIBS) -o $(TEST).$(EXESUFFIX)

run:
@echo ------------------------------------ executing test $(TEST)
$(TEST).$(EXESUFFIX)

verify: ;
19 changes: 19 additions & 0 deletions test/f90_correct/inc/bound13.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#

$(TEST): run

build: $(SRC)/$(TEST).f90
-$(RM) $(TEST).$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.*
@echo ------------------------------------ building test $@
-$(FC) -c $(FFLAGS) $(LDFLAGS) $(SRC)/$(TEST).f90 -o $(TEST).$(OBJX)
-$(FC) $(FFLAGS) $(LDFLAGS) $(TEST).$(OBJX) $(LIBS) -o $(TEST).$(EXESUFFIX)

run:
@echo ------------------------------------ executing test $(TEST)
$(TEST).$(EXESUFFIX)

verify: ;
19 changes: 19 additions & 0 deletions test/f90_correct/inc/bound14.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#

$(TEST): run

build: $(SRC)/$(TEST).F90
-$(RM) $(TEST).$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.*
@echo ------------------------------------ building test $@
-$(FC) -c $(FFLAGS) $(LDFLAGS) $(SRC)/$(TEST).F90 -o $(TEST).$(OBJX)
-$(FC) $(FFLAGS) $(LDFLAGS) $(TEST).$(OBJX) $(LIBS) -o $(TEST).$(EXESUFFIX)

run:
@echo ------------------------------------ executing test $(TEST)
$(TEST).$(EXESUFFIX)

verify: ;
19 changes: 19 additions & 0 deletions test/f90_correct/inc/bound15.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#

$(TEST): run

build: $(SRC)/$(TEST).f90
-$(RM) $(TEST).$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.*
@echo ------------------------------------ building test $@
-$(FC) -c $(FFLAGS) $(LDFLAGS) $(SRC)/$(TEST).f90 -o $(TEST).$(OBJX)
-$(FC) $(FFLAGS) $(LDFLAGS) $(TEST).$(OBJX) $(LIBS) -o $(TEST).$(EXESUFFIX)

run:
@echo ------------------------------------ executing test $(TEST)
$(TEST).$(EXESUFFIX)

verify: ;
19 changes: 19 additions & 0 deletions test/f90_correct/inc/bound16.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#

$(TEST): run

build: $(SRC)/$(TEST).f90
-$(RM) $(TEST).$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.*
@echo ------------------------------------ building test $@
-$(FC) -c $(FFLAGS) $(LDFLAGS) $(SRC)/$(TEST).f90 -o $(TEST).$(OBJX)
-$(FC) $(FFLAGS) $(LDFLAGS) $(TEST).$(OBJX) $(LIBS) -o $(TEST).$(EXESUFFIX)

run:
@echo ------------------------------------ executing test $(TEST)
$(TEST).$(EXESUFFIX)

verify: ;
19 changes: 19 additions & 0 deletions test/f90_correct/inc/bound2.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#

$(TEST): run

build: $(SRC)/$(TEST).f90
-$(RM) $(TEST).$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.*
@echo ------------------------------------ building test $@
-$(FC) -c $(FFLAGS) $(LDFLAGS) $(SRC)/$(TEST).f90 -o $(TEST).$(OBJX)
-$(FC) $(FFLAGS) $(LDFLAGS) $(TEST).$(OBJX) $(LIBS) -o $(TEST).$(EXESUFFIX)

run:
@echo ------------------------------------ executing test $(TEST)
$(TEST).$(EXESUFFIX)

verify: ;
19 changes: 19 additions & 0 deletions test/f90_correct/inc/bound3.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#

$(TEST): run

build: $(SRC)/$(TEST).f90
-$(RM) $(TEST).$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.*
@echo ------------------------------------ building test $@
-$(FC) -c $(FFLAGS) $(LDFLAGS) $(SRC)/$(TEST).f90 -o $(TEST).$(OBJX)
-$(FC) $(FFLAGS) $(LDFLAGS) $(TEST).$(OBJX) $(LIBS) -o $(TEST).$(EXESUFFIX)

run:
@echo ------------------------------------ executing test $(TEST)
$(TEST).$(EXESUFFIX)

verify: ;
19 changes: 19 additions & 0 deletions test/f90_correct/inc/bound4.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#

$(TEST): run

build: $(SRC)/$(TEST).f90
-$(RM) $(TEST).$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.*
@echo ------------------------------------ building test $@
-$(FC) -c $(FFLAGS) $(LDFLAGS) $(SRC)/$(TEST).f90 -o $(TEST).$(OBJX)
-$(FC) $(FFLAGS) $(LDFLAGS) $(TEST).$(OBJX) $(LIBS) -o $(TEST).$(EXESUFFIX)

run:
@echo ------------------------------------ executing test $(TEST)
$(TEST).$(EXESUFFIX)

verify: ;
19 changes: 19 additions & 0 deletions test/f90_correct/inc/bound5.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#

$(TEST): run

build: $(SRC)/$(TEST).f90
-$(RM) $(TEST).$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.*
@echo ------------------------------------ building test $@
-$(FC) -Hy,68,1 -My,68,1 -c $(FFLAGS) $(LDFLAGS) $(SRC)/$(TEST).f90 -o $(TEST).$(OBJX)
-$(FC) $(FFLAGS) $(LDFLAGS) $(TEST).$(OBJX) $(LIBS) -o $(TEST).$(EXESUFFIX)

run:
@echo ------------------------------------ executing test $(TEST)
$(TEST).$(EXESUFFIX)

verify: ;
19 changes: 19 additions & 0 deletions test/f90_correct/inc/bound6.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#

$(TEST): run

build: $(SRC)/$(TEST).f90
-$(RM) $(TEST).$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.*
@echo ------------------------------------ building test $@
-$(FC) -c $(FFLAGS) $(LDFLAGS) $(SRC)/$(TEST).f90 -o $(TEST).$(OBJX)
-$(FC) $(FFLAGS) $(LDFLAGS) $(TEST).$(OBJX) $(LIBS) -o $(TEST).$(EXESUFFIX)

run:
@echo ------------------------------------ executing test $(TEST)
$(TEST).$(EXESUFFIX)

verify: ;
19 changes: 19 additions & 0 deletions test/f90_correct/inc/bound7.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#

$(TEST): run

build: $(SRC)/$(TEST).f90
-$(RM) $(TEST).$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.*
@echo ------------------------------------ building test $@
-$(FC) -Hy,68,1 -My,68,1 -c $(FFLAGS) $(LDFLAGS) $(SRC)/$(TEST).f90 -o $(TEST).$(OBJX)
-$(FC) $(FFLAGS) $(LDFLAGS) $(TEST).$(OBJX) $(LIBS) -o $(TEST).$(EXESUFFIX)

run:
@echo ------------------------------------ executing test $(TEST)
$(TEST).$(EXESUFFIX)

verify: ;
19 changes: 19 additions & 0 deletions test/f90_correct/inc/bound8.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#

$(TEST): run

build: $(SRC)/$(TEST).f90
-$(RM) $(TEST).$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.*
@echo ------------------------------------ building test $@
-$(FC) -c $(FFLAGS) $(LDFLAGS) $(SRC)/$(TEST).f90 -o $(TEST).$(OBJX)
-$(FC) $(FFLAGS) $(LDFLAGS) $(TEST).$(OBJX) $(LIBS) -o $(TEST).$(EXESUFFIX)

run:
@echo ------------------------------------ executing test $(TEST)
$(TEST).$(EXESUFFIX)

verify: ;
14 changes: 14 additions & 0 deletions test/f90_correct/inc/bound9.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

build: $(SRC)/$(TEST).f90
@echo ------------------------------------ building test $(TEST)
-$(FC) -c $(SRC)/$(TEST).f90 > $(TEST).rslt 2>&1

run:
@echo ------------------------------------ nothing to run for test $(TEST)

verify: $(TEST).rslt
@echo ------------------------------------ verifying test $(TEST)
$(COMP_CHECK) $(SRC)/$(TEST).f90 $(TEST).rslt $(FC)
9 changes: 9 additions & 0 deletions test/f90_correct/lit/bound1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# Shared lit script for each tests. Run bash commands that run tests with make.

# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t
# RUN: cat %t | FileCheck %S/runmake
9 changes: 9 additions & 0 deletions test/f90_correct/lit/bound10.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# Shared lit script for each tests. Run bash commands that run tests with make.

# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t
# RUN: cat %t | FileCheck %S/runmake
9 changes: 9 additions & 0 deletions test/f90_correct/lit/bound11.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# Shared lit script for each tests. Run bash commands that run tests with make.

# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t
# RUN: cat %t | FileCheck %S/runmake
9 changes: 9 additions & 0 deletions test/f90_correct/lit/bound12.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# Shared lit script for each tests. Run bash commands that run tests with make.

# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t
# RUN: cat %t | FileCheck %S/runmake
9 changes: 9 additions & 0 deletions test/f90_correct/lit/bound13.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# Shared lit script for each tests. Run bash commands that run tests with make.

# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t
# RUN: cat %t | FileCheck %S/runmake
9 changes: 9 additions & 0 deletions test/f90_correct/lit/bound14.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# Shared lit script for each tests. Run bash commands that run tests with make.

# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t
# RUN: cat %t | FileCheck %S/runmake
9 changes: 9 additions & 0 deletions test/f90_correct/lit/bound15.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# Shared lit script for each tests. Run bash commands that run tests with make.

# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t
# RUN: cat %t | FileCheck %S/runmake
9 changes: 9 additions & 0 deletions test/f90_correct/lit/bound16.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# Shared lit script for each tests. Run bash commands that run tests with make.

# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t
# RUN: cat %t | FileCheck %S/runmake
9 changes: 9 additions & 0 deletions test/f90_correct/lit/bound2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# Shared lit script for each tests. Run bash commands that run tests with make.

# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t
# RUN: cat %t | FileCheck %S/runmake
Loading

1 comment on commit 2693fba

@pawosm-arm
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes the following regression (an ICE) when trying to build libmbd's mbd_methods.F90 file (see https://github.com/libmbd/libmbd/blob/master/src/mbd_methods.F90):

[ 60%] Building Fortran object src/CMakeFiles/mbd.dir/mbd_methods.F90.o
cd src && flang -Dmbd_EXPORTS -Isrc -g -fPIC -c src/mbd_methods.F90 -o CMakeFiles/mbd.dir/mbd_methods.F90.o
Lowering Error: symbol freq$sd is an inconsistent array descriptor
Lowering Error: symbol freq$sd is an inconsistent array descriptor
F90-F-0000-Internal compiler error. Errors in Lowering       2  (src/mbd_methods.F90: 154)
F90/aarch64 Linux Flang F90  - 1.5 2017-05-01: compilation aborted

Please sign in to comment.