public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/99368] New: ICE in build_function_decl, at fortran/trans-decl.c:2381
@ 2021-03-03 18:04 gscfq@t-online.de
  2021-03-03 21:42 ` [Bug fortran/99368] " anlauf at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gscfq@t-online.de @ 2021-03-03 18:04 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99368
           Summary: ICE in build_function_decl, at
                    fortran/trans-decl.c:2381
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gscfq@t-online.de
  Target Milestone: ---

This issue depends on alphabetical order of involved names,
that is, case z1 gives an ICE ("x"<"y"), z2 gives an error.
Special case: same name. Affects versions down to at least r5.


$ diff z1.f90 z2.f90
6c6
<       namelist /x/ y
---
>       namelist /z/ y


$ cat z1.f90
program p
   type y
   end type
contains
   subroutine s
      namelist /x/ y
      character(3) y
   end
end


$ cat z2.f90
program p
   type y
   end type
contains
   subroutine s
      namelist /z/ y
      character(3) y
   end
end


$ gfortran-11-20210228 -c z2.f90
z2.f90:6:17:

    6 |       namelist /z/ y
      |                 1
Error: PROCEDURE attribute conflicts with NAMELIST attribute in 'y' at (1)


$ gfortran-11-20210228 -c z1.f90
z1.f90:2:9:

    2 |    type y
      |         1
internal compiler error: in build_function_decl, at fortran/trans-decl.c:2381
0x752129 build_function_decl
        ../../gcc/fortran/trans-decl.c:2378
0x759a6c gfc_get_symbol_decl(gfc_symbol*)
        ../../gcc/fortran/trans-decl.c:1756
0x75c9a5 generate_namelist_decl
        ../../gcc/fortran/trans-decl.c:5241
0x75ce8e generate_local_nml_decl
        ../../gcc/fortran/trans-decl.c:6147
0x71af42 do_traverse_symtree
        ../../gcc/fortran/symbol.c:4170
0x75d011 generate_local_vars
        ../../gcc/fortran/trans-decl.c:6157
0x75d011 gfc_generate_function_code(gfc_namespace*)
        ../../gcc/fortran/trans-decl.c:6815
0x75cfe4 gfc_generate_contained_functions
        ../../gcc/fortran/trans-decl.c:5874
0x75cfe4 gfc_generate_function_code(gfc_namespace*)
        ../../gcc/fortran/trans-decl.c:6812
0x6e3a46 translate_all_program_units
        ../../gcc/fortran/parse.c:6351
0x6e3a46 gfc_parse_file()
        ../../gcc/fortran/parse.c:6620
0x72fd7f gfc_be_parse_file
        ../../gcc/fortran/f95-lang.c:212

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

* [Bug fortran/99368] ICE in build_function_decl, at fortran/trans-decl.c:2381
  2021-03-03 18:04 [Bug fortran/99368] New: ICE in build_function_decl, at fortran/trans-decl.c:2381 gscfq@t-online.de
@ 2021-03-03 21:42 ` anlauf at gcc dot gnu.org
  2021-08-01 17:04 ` kargl at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-03-03 21:42 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
   Last reconfirmed|                            |2021-03-03
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from anlauf at gcc dot gnu.org ---
Confirmed.

The error message for case z2 is misleading, too.  We should report
either a type conflict or better reject simply because the declaration
comes after the namelist statement.

I thought we had fixed this (see pr98686).

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

* [Bug fortran/99368] ICE in build_function_decl, at fortran/trans-decl.c:2381
  2021-03-03 18:04 [Bug fortran/99368] New: ICE in build_function_decl, at fortran/trans-decl.c:2381 gscfq@t-online.de
  2021-03-03 21:42 ` [Bug fortran/99368] " anlauf at gcc dot gnu.org
@ 2021-08-01 17:04 ` kargl at gcc dot gnu.org
  2023-05-29 21:48 ` kargl at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: kargl at gcc dot gnu.org @ 2021-08-01 17:04 UTC (permalink / raw)
  To: gcc-bugs

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

kargl at gcc dot gnu.org changed:

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

--- Comment #2 from kargl at gcc dot gnu.org ---
% gfc -c z1.f90

    2 |    type y
      |         1
......
    7 |       namelist /x/ y
      |                    2
Error: Derived type 'y' at (1) conflicts with namelist object 'y' at (2)

diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
index d148de3e3b5..6bde5707926 100644
--- a/gcc/fortran/match.c
+++ b/gcc/fortran/match.c
@@ -5551,10 +5582,32 @@ gfc_match_namelist (void)
                  gfc_error_check ();
                }
              else
-               /* If the type is not set already, we set it here to the
-                  implicit default type.  It is not allowed to set it
-                  later to any other type.  */
-               gfc_set_default_type (sym, 0, gfc_current_ns);
+               {
+                 /* Before the symbol is given an implicit type, check to
+                    see if the symbol is already available in the namespace,
+                    possibly through host association.  Importantly, the
+                    symbol may be a user defined type.  */
+
+                 gfc_symbol *tmp;
+
+                 gfc_find_symbol (sym->name, NULL, 1, &tmp);
+                 if (tmp
+                     && tmp->attr.generic
+                     && (tmp = gfc_find_dt_in_generic (tmp)))
+                   {
+                     if (tmp->attr.flavor == FL_DERIVED)
+                       {
+                         gfc_error ("Derived type %qs at %L conflicts with "
+                                    "namelist object %qs at %C", 
+                                    tmp->name, &tmp->declared_at, sym->name);
+                         goto error;
+                       }
+                   }
+
+                 /* Set type of the symbol to its implicit default type.  It
is
+                    not allowed to set it later to any other type.  */
+                 gfc_set_default_type (sym, 0, gfc_current_ns);
+               }
            }
          if (sym->attr.in_namelist == 0
              && !gfc_add_in_namelist (&sym->attr, sym->name, NULL))

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

* [Bug fortran/99368] ICE in build_function_decl, at fortran/trans-decl.c:2381
  2021-03-03 18:04 [Bug fortran/99368] New: ICE in build_function_decl, at fortran/trans-decl.c:2381 gscfq@t-online.de
  2021-03-03 21:42 ` [Bug fortran/99368] " anlauf at gcc dot gnu.org
  2021-08-01 17:04 ` kargl at gcc dot gnu.org
@ 2023-05-29 21:48 ` kargl at gcc dot gnu.org
  2023-05-29 21:58 ` kargl at gcc dot gnu.org
  2023-07-08 17:13 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: kargl at gcc dot gnu.org @ 2023-05-29 21:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from kargl at gcc dot gnu.org ---
Update patch to deal with the great *.c to *.cc rename event.  Patch passes
regression testing.

diff --git a/gcc/fortran/match.cc b/gcc/fortran/match.cc
index e7be7fddc64..c1920bc618d 100644
--- a/gcc/fortran/match.cc
+++ b/gcc/fortran/match.cc
@@ -5620,10 +5620,32 @@ gfc_match_namelist (void)
                  gfc_error_check ();
                }
              else
-               /* If the type is not set already, we set it here to the
-                  implicit default type.  It is not allowed to set it
-                  later to any other type.  */
-               gfc_set_default_type (sym, 0, gfc_current_ns);
+               {
+                 /* Before the symbol is given an implicit type, check to
+                    see if the symbol is already available in the namespace,
+                    possibly through host association.  Importantly, the
+                    symbol may be a user defined type.  */
+
+                 gfc_symbol *tmp;
+
+                 gfc_find_symbol (sym->name, NULL, 1, &tmp);
+                 if (tmp
+                     && tmp->attr.generic
+                     && (tmp = gfc_find_dt_in_generic (tmp)))
+                   {
+                     if (tmp->attr.flavor == FL_DERIVED)
+                       {
+                         gfc_error ("Derived type %qs at %L conflicts with "
+                                    "namelist object %qs at %C", 
+                                    tmp->name, &tmp->declared_at, sym->name);
+                         goto error;
+                       }
+                   }
+
+                 /* Set type of the symbol to its implicit default type.  It
is
+                    not allowed to set it later to any other type.  */
+                 gfc_set_default_type (sym, 0, gfc_current_ns);
+               }
            }
          if (sym->attr.in_namelist == 0
              && !gfc_add_in_namelist (&sym->attr, sym->name, NULL))

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

* [Bug fortran/99368] ICE in build_function_decl, at fortran/trans-decl.c:2381
  2021-03-03 18:04 [Bug fortran/99368] New: ICE in build_function_decl, at fortran/trans-decl.c:2381 gscfq@t-online.de
                   ` (2 preceding siblings ...)
  2023-05-29 21:48 ` kargl at gcc dot gnu.org
@ 2023-05-29 21:58 ` kargl at gcc dot gnu.org
  2023-07-08 17:13 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: kargl at gcc dot gnu.org @ 2023-05-29 21:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from kargl at gcc dot gnu.org ---
Created attachment 55190
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55190&action=edit
patch that fixes bug

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

* [Bug fortran/99368] ICE in build_function_decl, at fortran/trans-decl.c:2381
  2021-03-03 18:04 [Bug fortran/99368] New: ICE in build_function_decl, at fortran/trans-decl.c:2381 gscfq@t-online.de
                   ` (3 preceding siblings ...)
  2023-05-29 21:58 ` kargl at gcc dot gnu.org
@ 2023-07-08 17:13 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-08 17:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS 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:9a2eab6172a8067e2f63e0fa2bcd5b2190656303

commit r14-2397-g9a2eab6172a8067e2f63e0fa2bcd5b2190656303
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Sat Jul 8 18:13:23 2023 +0100

    Fortran: Fix default type bugs in gfortran [PR99139, PR99368]

    2023-07-08  Steve Kargl  <sgk@troutmask.apl.washington.edu>

    gcc/fortran
            PR fortran/99139
            PR fortran/99368
            * match.cc (gfc_match_namelist): Check for host associated or
            defined types before applying default type.
            (gfc_match_select_rank): Apply default type to selector of
            unknown type if possible.
            * resolve.cc (resolve_fl_variable): Do not apply local default
            initialization to assumed rank entities.

    gcc/testsuite/
            PR fortran/99139
            * gfortran.dg/pr99139.f90 : New test

            PR fortran/99368
            * gfortran.dg/pr99368.f90 : New test

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

end of thread, other threads:[~2023-07-08 17:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-03 18:04 [Bug fortran/99368] New: ICE in build_function_decl, at fortran/trans-decl.c:2381 gscfq@t-online.de
2021-03-03 21:42 ` [Bug fortran/99368] " anlauf at gcc dot gnu.org
2021-08-01 17:04 ` kargl at gcc dot gnu.org
2023-05-29 21:48 ` kargl at gcc dot gnu.org
2023-05-29 21:58 ` kargl at gcc dot gnu.org
2023-07-08 17:13 ` cvs-commit 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).