https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111781

--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Mikael Morin <mik...@gcc.gnu.org>:

https://gcc.gnu.org/g:44c0398e65347def316700911a51ca8b4ec0a411

commit r14-9618-g44c0398e65347def316700911a51ca8b4ec0a411
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Fri Mar 22 12:32:34 2024 +0100

    fortran: Fix specification expression error with dummy procedures
[PR111781]

    This fixes a spurious invalid variable in specification expression error.
    The error was caused on the testcase from the PR by two different bugs.
    First, the call to is_parent_of_current_ns was unable to recognize
    correct host association and returned false.  Second, an ad-hoc
    condition coming next was using a global variable previously improperly
    restored to false (instead of restoring it to its initial value).  The
    latter happened on the testcase because one dummy argument was a procedure,
    and checking that argument what causing a check of all its arguments with
    the (improper) reset of the flag at the end, and that preceded the check of
    the next argument.

    For the first bug, the wrong result of is_parent_of_current_ns is fixed by
    correcting the namespaces that function deals with, both the one passed
    as argument and the current one tracked in the gfc_current_ns global.  Two
    new functions are introduced to select the right namespace.

    Regarding the second bug, the problematic condition is removed, together
    with the formal_arg_flag associated with it.  Indeed, that condition was
    (wrongly) allowing local variables to be used in array bounds of dummy
    arguments.

            PR fortran/111781

    gcc/fortran/ChangeLog:

            * symbol.cc (gfc_get_procedure_ns, gfc_get_spec_ns): New functions.
            * gfortran.h (gfc_get_procedure_ns, gfc_get_spec ns): Declare them.
            (gfc_is_formal_arg): Remove.
            * expr.cc (check_restricted): Remove special case allowing local
            variable in dummy argument bound expressions.  Use gfc_get_spec_ns
            to get the right namespace.
            * resolve.cc (gfc_is_formal_arg, formal_arg_flag): Remove.
            (gfc_resolve_formal_arglist): Set gfc_current_ns.  Quit loop and
            restore gfc_current_ns instead of early returning.
            (resolve_symbol): Factor common array spec resolution code to...
            (resolve_symbol_array_spec): ... this new function.  Additionnally
            set and restore gfc_current_ns.

    gcc/testsuite/ChangeLog:

            * gfortran.dg/spec_expr_8.f90: New test.
            * gfortran.dg/spec_expr_9.f90: New test.

Reply via email to