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

32 lines
730 B
Fortran

! RUN: %python %S/test_errors.py %s %flang_fc1
! 15.6.2.5(3)
module m1
implicit logical(a-b)
interface
module subroutine sub1(a, b)
real, intent(in) :: a
real, intent(out) :: b
end
logical module function f()
end
end interface
end
submodule(m1) sm1
contains
module procedure sub1
!ERROR: Left-hand side of assignment is not definable
!BECAUSE: 'a' is an INTENT(IN) dummy argument
a = 1.0
b = 2.0
!ERROR: No intrinsic or user-defined ASSIGNMENT(=) matches operand types REAL(4) and LOGICAL(4)
b = .false.
end
module procedure f
f = .true.
!ERROR: No intrinsic or user-defined ASSIGNMENT(=) matches operand types LOGICAL(4) and REAL(4)
f = 1.0
end
end