Hi all,
I’m encountering an error when compiling a Fortran module that involves a subroutine with an alternate entry point, using the entry keyword. Here is a small example:
First, the module:
module entry_testing_m
implicit none
private
public :: foo, bar
contains
subroutine foo()
integer :: x, y, z
logical :: came_from_foo
came_from_foo = .true.
print *, 'came from foo'
x = 1
y = 2
entry bar()
if (.not. came_from_foo) then
print *, 'came from bar'
x = 1000
y = 2000
end if
z = x + y
print *, z
end subroutine foo
end module entry_testing_m
Next, the program that calls the subroutines:
program main_testing
use entry_testing_m, only: foo, bar
implicit none
print *, 'testing foo'
call foo()
print *, 'testing bar'
call bar()
end program main_testing
Finally, a makefile for the program:
# gfortran compiles and works correctly (prints 3, then 3000)
FC=gfortran
# nvfortran doesn't compile...
FC=nvfortran
FFLAGS=-g -O0
OBJS = entry_testing.o main_testing.o
moduletest.out: $(OBJS)
$(FC) $(FFLAGS) -o $@ $^
chmod +x $@
%.o: %.f90
$(FC) -c $(FFLAGS) -o $@ $^
clean:
rm -rf *.o *.mod moduletest.out
I can compile this code successfully using gfortran, and I get the expected output of 3 from foo and 3000 from bar. But nvfortran doesn’t seem to recognize the entry keyword, and the compilation fails:
nvfortran -c -g -O0 -o entry_testing.o entry_testing.f90
NVFORTRAN-W-0155-MODULE PROCEDURE not defined: bar (entry_testing.f90: 25)
0 inform, 1 warnings, 0 severes, 0 fatal for foo
nvfortran -c -g -O0 -o main_testing.o main_testing.f90
NVFORTRAN-S-0084-Illegal use of symbol bar - attempt to CALL a non-SUBROUTINE (main_testing.f90: 8)
0 inform, 0 warnings, 1 severes, 0 fatal for main_testing
make: *** [Makefile:18: main_testing.o] Error 2
Is this a bug with nvfortran or an error on my part?
I know this could be solved by defining bar as a separate subroutine instead of an entry to foo. In my real program, it would be possible to rewrite the code to not use such entries, but I would like to avoid refactoring like that as it would lead to duplicating a bunch of code with only 1-2 line differences.
Any advice is welcome. Thanks!