Fortran: Fix issues with unused/undefined variable warnings
Improves Fortran's unused and undefined variable warnings for allocatable arguments and intrinsic procedures.
This commit addresses a bug in the Fortran compiler where -Wunused-but-set and -Wundefined-vars warnings were not correctly issued for allocatable arguments and intrinsic procedures. It corrects how allocated status is tracked for arguments with various intents and ensures that warnings are issued in a more logical order when both -Wall and -Wextra are used. New test cases are included to cover these fixes.
In Details
This patch enhances the accuracy of static warnings related to variable usage in GFortran. It refines the tracking of sym->attr.allocated for variables that might be allocated via allocatable actual arguments, regardless of the formal argument's INTENT. It also adjusts warning emission order and ensures intrinsic procedures do not incorrectly trigger allocation-related warnings. The fix is related to PR fortran/126058.
- allocatable
- A Fortran keyword used to declare an array or derived-type component that can have its size or structure changed dynamically during program execution using the ALLOCATE and DEALLOCATE statements.
- INTENT(OUT)
- A Fortran attribute specifying that a procedure argument will be written to by the procedure and its initial value will not be preserved.
- -Wall
- A GCC command-line option that enables a wide range of warning messages.
- -Wextra
- A GCC command-line option that enables additional warning messages beyond those enabled by -Wall.
- symbol
- In the context of a compiler, a symbol table entry that represents an identifier such as a variable, function, or type.
- intrinsic procedure
- A procedure (function or subroutine) that is predefined by the Fortran language standard and available for use without explicit declaration.