Skip to content

Commit

Permalink
[flang] More tests
Browse files Browse the repository at this point in the history
Original-commit: flang-compiler/f18@bd5e95e
Reviewed-on: flang-compiler/f18#711
Tree-same-pre-rewrite: false
  • Loading branch information
klausler committed Sep 9, 2019
1 parent c19c1e5 commit 5ea5fe9
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 8 deletions.
2 changes: 1 addition & 1 deletion flang/test/semantics/call07.f90
Expand Up @@ -30,7 +30,7 @@ subroutine s03(p)
subroutine test
! ERROR: CONTIGUOUS pointer must be an array
real, pointer, contiguous :: a01 ! C830
real, pointer :: a02
real, pointer :: a02(:)
real, target :: a03(10)
real :: a04(10) ! not TARGET
call s01(a03) ! ok
Expand Down
83 changes: 80 additions & 3 deletions flang/test/semantics/call10.f90
Expand Up @@ -14,7 +14,7 @@

! Test 15.7 (C1583-C1590, C1592-C1599) constraints and restrictions
! for PURE procedures.
! (C1591 is tested in call11.f90.)
! (C1591 is tested in call11.f90; C1594 in call12.f90.)

module m

Expand All @@ -33,11 +33,17 @@ subroutine impure
end subroutine
end interface

real, volatile, target :: volatile

contains

subroutine impure(x)
type(impureFinal) :: x
end subroutine
integer impure function notpure(n)
integer, value :: n
notpure = n
end function

pure real function f01(a)
real, intent(in) :: a ! ok
Expand Down Expand Up @@ -125,7 +131,78 @@ pure subroutine s06(p) ! C1590
! ERROR: A dummy procedure of a PURE subprogram must be PURE.
procedure(impure) :: p
end subroutine

! pmk: Continue with C1592 - C1599
! C1591 is tested in call11.f90.
pure subroutine s07 ! C1592
contains
pure subroutine pure ! ok
end subroutine
! ERROR: An internal subprogram of a PURE subprogram must also be PURE.
subroutine impure1
end subroutine
! ERROR: An internal subprogram of a PURE subprogram must also be PURE.
impure subroutine impure2
end subroutine
end subroutine
function volptr
real, pointer, volatile :: volptr
volptr => volatile
end function
pure subroutine s08 ! C1593
real :: x
! ERROR: A VOLATILE variable may not appear in a PURE subprogram.
x = volatile
! ERROR: A VOLATILE variable may not appear in a PURE subprogram.
x = volptr
end subroutine
! C1594 is tested in call12.f90.
pure subroutine s09 ! C1595
integer :: n
! ERROR: Any procedure referenced in a PURE subprogram must also be PURE.
n = notpure(1)
end subroutine
pure subroutine s10(to) ! C1596
type(polyAlloc) :: auto, to
! ERROR: Deallocation of a polymorphic object is not permitted in a PURE subprogram.
to = auto
! Implicit deallocation at the end of the subroutine:
! ERROR: Deallocation of a polymorphic object is not permitted in a PURE subprogram.
end subroutine
pure subroutine s11
character :: buff(20)
real :: x
write(buff, *) 1.0 ! ok
read(buff, *) x ! ok
! ERROR: External I/O is not allowed in a PURE subprogram
print *, 'hi' ! C1597
! ERROR: External I/O is not allowed in a PURE subprogram
open(1, 'launch-codes') ! C1597
! ERROR: External I/O is not allowed in a PURE subprogram
close(1) ! C1597
! ERROR: External I/O is not allowed in a PURE subprogram
backspace(1) ! C1597
! ERROR: External I/O is not allowed in a PURE subprogram
endfile(1) ! C1597
! ERROR: External I/O is not allowed in a PURE subprogram
rewind(1) ! C1597
! ERROR: External I/O is not allowed in a PURE subprogram
flush(1) ! C1597
! ERROR: External I/O is not allowed in a PURE subprogram
wait(1) ! C1597
! ERROR: External I/O is not allowed in a PURE subprogram
inquire(1, name=buff) ! C1597
! ERROR: External I/O is not allowed in a PURE subprogram
read(5, *) x ! C1598
! ERROR: External I/O is not allowed in a PURE subprogram
read(*, *) x ! C1598
! ERROR: External I/O is not allowed in a PURE subprogram
write(6, *) ! C1598
! ERROR: External I/O is not allowed in a PURE subprogram
write(*, *) ! C1598
end subroutine
pure subroutine s12
! ERROR: An image control statement is not allowed in a PURE subprogram.
sync all ! C1599
! TODO others from 11.6.1 (many)
end subroutine

end module
8 changes: 4 additions & 4 deletions flang/test/semantics/call11.f90
Expand Up @@ -18,12 +18,12 @@ module m

type :: t
contains
procedure :: tbp => pure
procedure, nopass :: tbp => pure
end type
type, extends(t) :: t2
contains
! ERROR: An overridden PURE type-bound procedure binding must also be PURE
procedure :: tbp => impure ! 7.5.7.3
procedure, nopass :: tbp => impure ! 7.5.7.3
end type

contains
Expand All @@ -45,9 +45,9 @@ subroutine test
! ERROR: A procedure referenced in a FORALL body must be PURE.
a(j) = impure(j) ! C1037
end forall
! ERROR: A procedure referenced in a mask expression must be PURE.
! ERROR: concurrent-header mask expression cannot reference an impure procedure
do concurrent (j=1:1, impure(j) /= 0) ! C1121
! ERROR: A procedure referenced in a DO CONCURRENT body must be PURE.
! ERROR: call to impure subroutine in DO CONCURRENT not allowed
a(j) = impure(j) ! C1139
end do
end subroutine
Expand Down

0 comments on commit 5ea5fe9

Please sign in to comment.