Fortran fixes a bug where `always_explicit` attribute was not copied.
A bug in Fortran's `gfc_copy_attr` prevented `always_explicit` from being copied, leading to incorrect array handling and potential garbage values.
This commit fixes a bug in the Fortran frontend where the always_explicit attribute was not copied during symbol duplication in submodules. This omission caused array constructors to be incorrectly passed as raw data pointers instead of proper array descriptors. Consequently, callers expecting assumed-shape dummy arguments would read garbage bounds, leading to runtime errors and incorrect program behavior.
In Details
The fix addresses a symbol attribute propagation issue within GCC's Fortran frontend, specifically in symbol.cc. The gfc_copy_attr function failed to copy the always_explicit attribute. This becomes problematic when gfc_copy_dummy_sym creates a new dummy procedure symbol within a submodule module procedure (gfc_match_submod_proc), as the attribute loss leads to nodesc_arg being set incorrectly at translation time for calls, thus misrepresenting array arguments.
For Context
In Fortran, programs can be organized into modules and submodules, which allow for code reuse and modular design. Compilers, like GCC, create internal representations of these program elements, including symbols for procedures and their attributes. This commit fixes a bug where a specific attribute, always_explicit, was not being correctly copied when the compiler duplicated symbols, particularly when dealing with procedures in submodules. This error meant that instead of passing complete descriptions of arrays, the compiler would sometimes pass only raw data pointers. When other parts of the code expected a full array description, they would then read incorrect information, leading to program crashes or wrong results. This fix ensures that the always_explicit attribute is always properly propagated, resolving these issues.