Files
llvm-project/flang/test/Semantics/bindings03.f90
Peter Klausler 5fc77c1666 [flang] Add new warnings for unused & undefined locals (#173504)
Add a requested warning for completely unused local variables. The
implementation runs a scan over typed expressions during the existing
expression semantics pass to detect variable uses, and a routine at the
end of semantics to take a pass over the symbol tables to find unused
locals.

The new infrastructure needed to detect variable uses, and the existing
infrastructure that detects potential variable definitions, then makes
it easy to detect variables that are used without any possible
initialization or definition, so I did that too.

The warning for unused locals is off by default -- they might indicate a
misspelling (that IMPLICIT NONE would have caught), but seem otherwise
generally benign. The warning for uses of completely uninitialized and
undefined variables, however, is enabled by default, since that's likely
to indicate a program bug that should be investigated.

This patch touches a lot of files lightly. Many of these files are tests
that would have produced needless warning noise; one new test was added.

Fixes https://github.com/llvm/llvm-project/issues/173276.
2025-12-31 12:42:06 -08:00

28 lines
737 B
Fortran

! RUN: %python %S/test_errors.py %s %flang_fc1 -Werror -pedantic
! Confirm a portability warning on use of a procedure binding apart from a call
module m
type t
contains
procedure :: sub
end type
contains
subroutine sub(x)
class(t), intent(in) :: x
end subroutine
end module
program test
use m
procedure(sub), pointer :: p
!WARNING: Value of local variable 'x' is never used [-Wunused-variable]
type(t) x
!PORTABILITY: Procedure binding 'sub' used as target of a pointer assignment [-Wbinding-as-procedure]
p => x%sub
!PORTABILITY: Procedure binding 'sub' passed as an actual argument [-Wbinding-as-procedure]
call sub2(x%sub)
contains
subroutine sub2(s)
procedure(sub) s
end subroutine
end