llvm-project/flang/test/Semantics/intrinsics04.f90
Peter Klausler 97e3f605d5
[flang] Don't allow non-standard data conversions of potentially abse… (#87391)
…nt arguments

Arguments to the intrinsic functions MAX and MIN after the first two are
optional. When these actual arguments might not be present at run time,
emit a compilation time error if they require data conversion (a
non-standard but nearly universal language extension); such a conversion
would crash if the argument was absent.

Other compilers either disallow data conversions entirely on MAX/MIN or
crash at run time if a converted argument is absent.

Fixes https://github.com/llvm/llvm-project/issues/87046.
2024-04-08 11:56:36 -07:00

26 lines
1.2 KiB
Fortran

! RUN: %python %S/test_errors.py %s %flang_fc1
! A potentially absent actual argument cannot require data type conversion.
subroutine s(o,a,p)
integer(2), intent(in), optional :: o
integer(2), intent(in), allocatable :: a
integer(2), intent(in), pointer :: p
!ERROR: An actual argument to MAX/MIN requiring data conversion may not be OPTIONAL, POINTER, or ALLOCATABLE
print *, max(1, 2, o)
!ERROR: An actual argument to MAX/MIN requiring data conversion may not be OPTIONAL, POINTER, or ALLOCATABLE
print *, max(1, 2, a)
!ERROR: An actual argument to MAX/MIN requiring data conversion may not be OPTIONAL, POINTER, or ALLOCATABLE
print *, max(1, 2, p)
!ERROR: An actual argument to MAX/MIN requiring data conversion may not be OPTIONAL, POINTER, or ALLOCATABLE
print *, min(1, 2, o)
!ERROR: An actual argument to MAX/MIN requiring data conversion may not be OPTIONAL, POINTER, or ALLOCATABLE
print *, min(1, 2, a)
!ERROR: An actual argument to MAX/MIN requiring data conversion may not be OPTIONAL, POINTER, or ALLOCATABLE
print *, min(1, 2, p)
print *, max(1_2, 2_2, o) ! ok
print *, max(1_2, 2_2, a) ! ok
print *, max(1_2, 2_2, p) ! ok
print *, min(1_2, 2_2, o) ! ok
print *, min(1_2, 2_2, a) ! ok
print *, min(1_2, 2_2, p) ! ok
end