llvm/flang/test/Semantics/resolve59.f90
Tim Keith 99aa87a5b5 [flang][NFC] Simplify semantics test scripts
There were several different ways of handling the option to f18 to
find predefined modules:
- test_errors.sh was created by cmake substituting
  FLANG_INTRINSIC_MODULES_DIR into test_errors.sh.in
- some tests used the flang script which has the option built it
- some tests used %f18_with_includes which was replaced by the path
  to f18 plus the -I option
- some included -I../../include/flang in their run command

To make this more consistent, change %f18 to include the
-intrinsic-module-directory option and use it everywhere, including
to replace %flang and %f18_with_includes. This requires changing all
of the invocations of the test scripts to put %f18 at the end so that
it can expand to more than one argument.

This eliminates the need to generate test_errors.sh which means we
don't need flang/test/Semantics/CMakeLists.txt or the %B substitution.
That makes the test_errors.sh command like the others, replacing
%B/test/Semantics/test_errors.sh with %S/test_errors.sh.

Also remove the OPTIONS: functionality as custom options can be included
in the RUN: command. And remove -I/../../include/flang as that is now
always included.

Differential Revision: https://reviews.llvm.org/D79634
2020-05-11 11:49:25 -07:00

139 lines
3.3 KiB
Fortran

! RUN: %S/test_errors.sh %s %t %f18
! Testing 15.6.2.2 point 4 (What function-name refers to depending on the
! presence of RESULT).
module m_no_result
! Without RESULT, it refers to the result object (no recursive
! calls possible)
contains
! testing with data object results
function f1()
real :: x, f1
!ERROR: 'f1' is not a function
x = acos(f1())
f1 = x
x = acos(f1) !OK
end function
function f2(i)
integer i
real :: x, f2
!ERROR: 'f2' is not an array
x = acos(f2(i+1))
f2 = x
x = acos(f2) !OK
end function
function f3(i)
integer i
real :: x, f3(1)
! OK reference to array result f1
x = acos(f3(i+1))
f3 = x
x = sum(acos(f3)) !OK
end function
! testing with function pointer results
function rf()
real :: rf
end function
function f4()
procedure(rf), pointer :: f4
f4 => rf
! OK call to f4 pointer (rf)
x = acos(f4())
!ERROR: Actual argument for 'x=' may not be a procedure
x = acos(f4)
end function
function f5(x)
real :: x
interface
real function rfunc(x)
real, intent(in) :: x
end function
end interface
procedure(rfunc), pointer :: f5
f5 => rfunc
! OK call to f5 pointer
x = acos(f5(x+1))
!ERROR: Actual argument for 'x=' may not be a procedure
x = acos(f5)
end function
! Sanity test: f18 handles C1560 violation by ignoring RESULT
function f6() result(f6) !OKI (warning)
end function
function f7() result(f7) !OKI (warning)
real :: x, f7
!ERROR: 'f7' is not a function
x = acos(f7())
f7 = x
x = acos(f7) !OK
end function
end module
module m_with_result
! With RESULT, it refers to the function (recursive calls possible)
contains
! testing with data object results
function f1() result(r)
real :: r
r = acos(f1()) !OK, recursive call
!ERROR: Actual argument for 'x=' may not be a procedure
x = acos(f1)
end function
function f2(i) result(r)
integer i
real :: r
r = acos(f2(i+1)) ! OK, recursive call
!ERROR: Actual argument for 'x=' may not be a procedure
r = acos(f2)
end function
function f3(i) result(r)
integer i
real :: r(1)
r = acos(f3(i+1)) !OK recursive call
!ERROR: Actual argument for 'x=' may not be a procedure
r = sum(acos(f3))
end function
! testing with function pointer results
function rf()
real :: rf
end function
function f4() result(r)
real :: x
procedure(rf), pointer :: r
r => rf
!ERROR: Actual argument for 'x=' may not be a procedure
x = acos(f4()) ! recursive call
!ERROR: Actual argument for 'x=' may not be a procedure
x = acos(f4)
x = acos(r()) ! OK
end function
function f5(x) result(r)
real :: x
procedure(acos), pointer :: r
r => acos
!ERROR: Actual argument for 'x=' may not be a procedure
x = acos(f5(x+1)) ! recursive call
!ERROR: Actual argument for 'x=' may not be a procedure
x = acos(f5)
x = acos(r(x+1)) ! OK
end function
! testing that calling the result is also caught
function f6() result(r)
real :: x, r
!ERROR: 'r' is not a function
x = r()
end function
end module
subroutine array_rank_test()
real :: x(10, 10), y
!ERROR: Reference to rank-2 object 'x' has 1 subscripts
y = x(1)
!ERROR: Reference to rank-2 object 'x' has 3 subscripts
y = x(1, 2, 3)
end