Files
clang-p2996/flang/test/Semantics/nullify02.f90
Peter Klausler 573fc6187b [flang] Fix pointer definition semantic checking via refactoring
The infrastructure in semantics that is used to check that the
left-hand sides of normal assignment statements are really definable
variables was not being used to check whether the LHSs of pointer assignments
are modifiable, and so most cases of unmodifiable pointers are left
undiagnosed.  Rework the semantics checking for pointer assignments,
NULLIFY statements, pointer dummy arguments, &c. so that cases of
unmodifiable pointers are properly caught.  This has been done
by extracting all the various definability checking code that has
been implemented for different contexts in Fortran into one new
facility.

The new consolidated definability checking code returns messages
meant to be attached as "because: " explanations to context-dependent
errors like "left-hand side of assignment is not definable".
These new error message texts and their attached explanations
affect many existing tests, which have been updated.  The testing
infrastructure was extended by another patch to properly compare
warnings and explanatory messages, which had been ignored until
recently.

Differential Revision: https://reviews.llvm.org/D136979
2022-10-31 12:02:21 -07:00

57 lines
1.2 KiB
Fortran

! RUN: %python %S/test_errors.py %s %flang_fc1
! Check for semantic errors in NULLIFY statements
INTEGER, PARAMETER :: maxvalue=1024
Type dt
Integer :: l = 3
End Type
Type t
Type(dt) :: p
End Type
Type(t),Allocatable :: x(:)
Integer :: pi
Procedure(Real) :: prp
Allocate(x(3))
!ERROR: 'p' may not appear in NULLIFY
!BECAUSE: 'p' is not a pointer
Nullify(x(2)%p)
!ERROR: 'pi' may not appear in NULLIFY
!BECAUSE: 'pi' is not a pointer
Nullify(pi)
!ERROR: 'prp' may not appear in NULLIFY
!BECAUSE: 'prp' is not a pointer
Nullify(prp)
!ERROR: 'maxvalue' may not appear in NULLIFY
!BECAUSE: 'maxvalue' is not a pointer
Nullify(maxvalue)
End Program
! Make sure that the compiler doesn't crash when NULLIFY is used in a context
! that has reported errors
module badNullify
interface
function ptrFun()
integer, pointer :: ptrFun
end function
end interface
contains
!ERROR: 'ptrfun' was not declared a separate module procedure
!ERROR: 'ptrfun' is already declared in this scoping unit
module function ptrFun()
integer, pointer :: ptrFun
real :: realVar
nullify(ptrFun)
!ERROR: 'realvar' may not appear in NULLIFY
!BECAUSE: 'realvar' is not a pointer
nullify(realVar)
end function
end module