public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/114280] New: ASSOCIATE fails with inquiry references when selector function not yet parsed.
@ 2024-03-08  8:55 pault at gcc dot gnu.org
  2024-03-08 15:22 ` [Bug fortran/114280] " law at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: pault at gcc dot gnu.org @ 2024-03-08  8:55 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114280
           Summary: ASSOCIATE fails with inquiry references when selector
                    function not yet parsed.
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pault at gcc dot gnu.org
  Target Milestone: ---

Fails identically back to 6.4.1 at least:

  implicit none
  type t
     real :: re
  end type t
  call foo
contains
  subroutine foo ()
    associate (x => bar1())
      print *, x%im          ! Has no IMPLICIT type
    end associate

    associate (x => bar1())
      print *, x%re          ! Invalid character in name
    end associate

    associate (x => bar2())
      print *, x%re          ! Invalid character in name
    end associate

    associate (x => bar3())
      print *, x%len          ! Has no IMPLICIT type
    end associate
  end
  complex function bar1 ()
    bar1 = cmplx(-42., 1.)
  end
  type(t) function bar2 ()
    bar2% re = 42.
  end
  character(8) function bar3 ()
    bar3 = "Nice one!"
  end
end

Works if:
(i) subroutine foo is placed after functions bar[1-3]; or
(ii) if intrinsics real, imag and len are used instead of inquiry references
and component 're' is renamed.

This bug appears for the same reason as PR99065.

Paul


Paul

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug fortran/114280] ASSOCIATE fails with inquiry references when selector function not yet parsed.
  2024-03-08  8:55 [Bug fortran/114280] New: ASSOCIATE fails with inquiry references when selector function not yet parsed pault at gcc dot gnu.org
@ 2024-03-08 15:22 ` law at gcc dot gnu.org
  2024-03-15  6:53 ` cvs-commit at gcc dot gnu.org
  2024-03-15  7:09 ` pault at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: law at gcc dot gnu.org @ 2024-03-08 15:22 UTC (permalink / raw)
  To: gcc-bugs

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

Jeffrey A. Law <law at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |law at gcc dot gnu.org
           Priority|P3                          |P4

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug fortran/114280] ASSOCIATE fails with inquiry references when selector function not yet parsed.
  2024-03-08  8:55 [Bug fortran/114280] New: ASSOCIATE fails with inquiry references when selector function not yet parsed pault at gcc dot gnu.org
  2024-03-08 15:22 ` [Bug fortran/114280] " law at gcc dot gnu.org
@ 2024-03-15  6:53 ` cvs-commit at gcc dot gnu.org
  2024-03-15  7:09 ` pault at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-15  6:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Paul Thomas <pault@gcc.gnu.org>:

https://gcc.gnu.org/g:3fd46d859cda1074125449a4cc680ce59fcebc38

commit r14-9489-g3fd46d859cda1074125449a4cc680ce59fcebc38
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Fri Mar 15 06:52:59 2024 +0000

    Fortran: Fix class/derived/complex function associate selectors [PR87477]

    2024-03-15  Paul Thomas  <pault@gcc.gnu.org>

    gcc/fortran
            PR fortran/87477
            PR fortran/89645
            PR fortran/99065
            PR fortran/114141
            PR fortran/114280
            * class.cc (gfc_change_class): New function needed for
            associate names, when rank changes or a derived type is
            produced by resolution
            * dump-parse-tree.cc (show_code_node): Make output for SELECT
            TYPE more comprehensible.
            * expr.cc (find_inquiry_ref): Do not simplify expressions of
            an inferred type.
            * gfortran.h : Add 'gfc_association_list' to structure
            'gfc_association_list'. Add prototypes for
            'gfc_find_derived_types', 'gfc_fixup_inferred_type_refs' and
            'gfc_change_class'. Add macro IS_INFERRED_TYPE.
            * match.cc (copy_ts_from_selector_to_associate): Add bolean arg
            'select_type' with default false. If this is a select type name
            and the selector is a inferred type, build the class type and
            apply it to the associate name.
            (build_associate_name): Pass true to 'select_type' in call to
            previous.
            * parse.cc (parse_associate): If the selector is inferred type
            the associate name is too. Make sure that function selector
            class and rank, if known, are passed to the associate name. If
            a function result exists, pass its typespec to the associate
            name.
            * primary.cc (resolvable_fcns): New function to check that all
            the function references are resolvable.
            (gfc_match_varspec): If a scalar derived type select type
            temporary has an array reference, match the array reference,
            treating this in the same way as an equivalence member. Do not
            set 'inquiry' if applied to an unknown type the inquiry name
            is ambiguous with the component of an accessible derived type.
            Check that resolution of the target expression is OK by testing
            if the symbol is declared or is an operator expression, then
            using 'resolvable_fcns' recursively. If all is well, resolve
            the expression. If this is an inferred type with a component
            reference, call 'gfc_find_derived_types' to find a suitable
            derived type. If there is an inquiry ref and the symbol either
            is of unknown type or is inferred to be a derived type, set the
            primary and symbol TKR appropriately.
            * resolve.cc (resolve_variable): Call new function below.
            (gfc_fixup_inferred_type_refs): New function to ensure that the
            expression references for a inferred type are consistent with
            the now fixed up selector.
            (resolve_assoc_var): Ensure that derived type or class function
            selectors transmit the correct arrayspec to the associate name.
            (resolve_select_type): If the selector is an associate name of
            inferred type and has no component references, the associate
            name should have its typespec. Simplify the conversion of a
            class array to class scalar by calling 'gfc_change_class'.
            Make sure that a class, inferred type selector with an array
            ref transfers the typespec from the symbol to the expression.
            * symbol.cc (gfc_set_default_type): If an associate name with
            unknown type has a selector expression, try resolving the expr.
            (find_derived_types, gfc_find_derived_types): New functions
            that search for a derived type with a given name.
            * trans-expr.cc (gfc_conv_variable): Some inferred type exprs
            escape resolution so call 'gfc_fixup_inferred_type_refs'.
            * trans-stmt.cc (trans_associate_var): Tidy up expression for
            'class_target'. Finalize and free class function results.
            Correctly handle selectors that are class functions and class
            array references, passed as derived types.

    gcc/testsuite/
            PR fortran/87477
            PR fortran/89645
            PR fortran/99065
            * gfortran.dg/associate_64.f90 : New test
            * gfortran.dg/associate_66.f90 : New test
            * gfortran.dg/associate_67.f90 : New test

            PR fortran/114141
            * gfortran.dg/associate_65.f90 : New test

            PR fortran/114280
            * gfortran.dg/associate_68.f90 : New test

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug fortran/114280] ASSOCIATE fails with inquiry references when selector function not yet parsed.
  2024-03-08  8:55 [Bug fortran/114280] New: ASSOCIATE fails with inquiry references when selector function not yet parsed pault at gcc dot gnu.org
  2024-03-08 15:22 ` [Bug fortran/114280] " law at gcc dot gnu.org
  2024-03-15  6:53 ` cvs-commit at gcc dot gnu.org
@ 2024-03-15  7:09 ` pault at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pault at gcc dot gnu.org @ 2024-03-15  7:09 UTC (permalink / raw)
  To: gcc-bugs

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

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

--- Comment #2 from Paul Thomas <pault at gcc dot gnu.org> ---
This mega-patch, on the scale of the importance of the problem, was required
because of gfortran's one pass parsing. It might be a temporary fix because I
am contemplating how an initial pass of contained procedures might be
introduced.

Fixed on mainline.

Paul

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-15  7:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-08  8:55 [Bug fortran/114280] New: ASSOCIATE fails with inquiry references when selector function not yet parsed pault at gcc dot gnu.org
2024-03-08 15:22 ` [Bug fortran/114280] " law at gcc dot gnu.org
2024-03-15  6:53 ` cvs-commit at gcc dot gnu.org
2024-03-15  7:09 ` pault at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).