Fortran requires MODULE prefix for separate module procedures
The Fortran compiler now correctly enforces the `MODULE` prefix for separate module procedures, preventing incorrect linking and improving diagnostic messages.
The Fortran compiler was incorrectly suppressing a diagnostic for missing MODULE prefixes on separate module procedures when they were made accessible through host association in submodules. This allowed incorrectly linked code to compile. The compiler now uses the module_procedure attribute, which is not cleared during host association, to guard the diagnostic. This restores the intended error message and provides a clearer explanation of the requirement, ensuring correct handling of separate module procedures.
In Details
The Fortran frontend's decl.cc file manages declarations, including how procedure names are handled. Specifically, get_proc_name performs checks related to module procedures. The bug arose because set_syms_host_assoc clears the external attribute on module procedures when they are made accessible via host association, which get_proc_name was incorrectly using as a guard for the missing MODULE prefix diagnostic. The fix replaces sym->attr.external with sym->attr.module_procedure, which persists across host association, thereby correctly enabling the diagnostic. The use of `gfc_…
For Context
Compilers translate human-readable source code into machine code. In Fortran, 'modules' are used to organize code, and 'module procedures' are functions or subroutines defined within them. 'Separate module procedures' are declared in a module but defined elsewhere. To ensure correctness, these separate definitions require a MODULE prefix. A bug in the Fortran compiler was causing it to incorrectly suppress an error message when this MODULE prefix was missing, especially when using 'host association' (a way for sub-modules to access declarations from a parent module). This could lead to the compiler accepting and incorrectly linking code that should have failed. The fix ensures the compiler always enforces the MODULE prefix, provides a clear error message, and prevents subsequent errors that might have been caused by the initial incorrect compilation.