public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/107068] New: Run-time error when reading logical arrays with a namelist
@ 2022-09-28 13:16 r.m.potvliege at durham dot ac.uk
  2022-09-28 13:28 ` [Bug fortran/107068] " r.m.potvliege at durham dot ac.uk
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: r.m.potvliege at durham dot ac.uk @ 2022-09-28 13:16 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107068
           Summary: Run-time error when reading logical arrays with a
                    namelist
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: r.m.potvliege at durham dot ac.uk
  Target Milestone: ---

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

* [Bug fortran/107068] Run-time error when reading logical arrays with a namelist
  2022-09-28 13:16 [Bug fortran/107068] New: Run-time error when reading logical arrays with a namelist r.m.potvliege at durham dot ac.uk
@ 2022-09-28 13:28 ` r.m.potvliege at durham dot ac.uk
  2022-09-28 18:23 ` [Bug libfortran/107068] " anlauf at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: r.m.potvliege at durham dot ac.uk @ 2022-09-28 13:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Robert Potvliege <r.m.potvliege at durham dot ac.uk> ---
Reading a logical array through a namelist triggers an (apparently) spurious
run time error in some cases. E.g., when I am compiling the following code with
gfortran,

      program test
      logical, dimension(3,3) :: flc,flp
      namelist/inputdata/flc,flp
!
      read(5,inputdata)
!
      end program test

and read the following file,

&INPUTDATA
 FLC = T,
 FLP(1,2) = T,
/

the execution stops with the error message

At line 5 of file progtest.f90 (unit = 5, file = 'stdin')
Fortran runtime error: Bad repeat count in item 1 of list input

However, there is no error for the following input file

&INPUTDATA
 FLC = T,
 FLP = T,
/

or the following one

&INPUTDATA
 FLP(1,2) = T,
/

etc. No error is produced for any of these input files if I compile this short
program with the Intel compiler I can access rather than gfortran.

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

* [Bug libfortran/107068] Run-time error when reading logical arrays with a namelist
  2022-09-28 13:16 [Bug fortran/107068] New: Run-time error when reading logical arrays with a namelist r.m.potvliege at durham dot ac.uk
  2022-09-28 13:28 ` [Bug fortran/107068] " r.m.potvliege at durham dot ac.uk
@ 2022-09-28 18:23 ` anlauf at gcc dot gnu.org
  2022-09-28 20:25 ` r.m.potvliege at durham dot ac.uk
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-09-28 18:23 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
          Component|fortran                     |libfortran
   Last reconfirmed|                            |2022-09-28

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

Renaming the second variable (e.g. flp -> xlp) works around the problem,
as well as interchanging the lines in the namelist input.

It appears that while scanning the namelist input we first see the T,
then F, for which we try to determine if it means .false. or is part of
a variable name, and then possibly screw up because we see a comma when
referring to an element of rank-2 array flp.

There is also no error when using a rank-1 array for flp and referring
to flp(2) etc.

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

* [Bug libfortran/107068] Run-time error when reading logical arrays with a namelist
  2022-09-28 13:16 [Bug fortran/107068] New: Run-time error when reading logical arrays with a namelist r.m.potvliege at durham dot ac.uk
  2022-09-28 13:28 ` [Bug fortran/107068] " r.m.potvliege at durham dot ac.uk
  2022-09-28 18:23 ` [Bug libfortran/107068] " anlauf at gcc dot gnu.org
@ 2022-09-28 20:25 ` r.m.potvliege at durham dot ac.uk
  2022-09-28 20:26 ` r.m.potvliege at durham dot ac.uk
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: r.m.potvliege at durham dot ac.uk @ 2022-09-28 20:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Robert Potvliege <r.m.potvliege at durham dot ac.uk> ---
Thanks for looking into this so quickly and for the work-round.

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

* [Bug libfortran/107068] Run-time error when reading logical arrays with a namelist
  2022-09-28 13:16 [Bug fortran/107068] New: Run-time error when reading logical arrays with a namelist r.m.potvliege at durham dot ac.uk
                   ` (2 preceding siblings ...)
  2022-09-28 20:25 ` r.m.potvliege at durham dot ac.uk
@ 2022-09-28 20:26 ` r.m.potvliege at durham dot ac.uk
  2023-05-13 19:44 ` jvdelisle at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: r.m.potvliege at durham dot ac.uk @ 2022-09-28 20:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Robert Potvliege <r.m.potvliege at durham dot ac.uk> ---
Thanks for looking into this so quickly and for the work-round.

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

* [Bug libfortran/107068] Run-time error when reading logical arrays with a namelist
  2022-09-28 13:16 [Bug fortran/107068] New: Run-time error when reading logical arrays with a namelist r.m.potvliege at durham dot ac.uk
                   ` (3 preceding siblings ...)
  2022-09-28 20:26 ` r.m.potvliege at durham dot ac.uk
@ 2023-05-13 19:44 ` jvdelisle at gcc dot gnu.org
  2023-05-14  1:30 ` jvdelisle at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2023-05-13 19:44 UTC (permalink / raw)
  To: gcc-bugs

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

Jerry DeLisle <jvdelisle at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jvdelisle at gcc dot gnu.org
           Assignee|unassigned at gcc dot gnu.org      |jvdelisle at gcc dot gnu.org

--- Comment #5 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
I will get looking at this since it is namelist related.

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

* [Bug libfortran/107068] Run-time error when reading logical arrays with a namelist
  2022-09-28 13:16 [Bug fortran/107068] New: Run-time error when reading logical arrays with a namelist r.m.potvliege at durham dot ac.uk
                   ` (4 preceding siblings ...)
  2023-05-13 19:44 ` jvdelisle at gcc dot gnu.org
@ 2023-05-14  1:30 ` jvdelisle at gcc dot gnu.org
  2023-05-14  3:34 ` jvdelisle at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2023-05-14  1:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
What is happening here is that in the name list input, the variable flp is also
a legal LOGICAL value, so our read is interpreting it as the second value of
the array flc and trying to continue to read values for flc. It encounters the
( and throws the error.

To resolve this, I think I will have to check for a valid variable name for
each value.

[aside: A lot of these issues stem from the weaknesses in how namelists are
interpreted.  There are ambiguities in the specification.]

My next step here is to go through the F2018 standard just to make sure what we
do is valid or invalid. (cheers)

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

* [Bug libfortran/107068] Run-time error when reading logical arrays with a namelist
  2022-09-28 13:16 [Bug fortran/107068] New: Run-time error when reading logical arrays with a namelist r.m.potvliege at durham dot ac.uk
                   ` (5 preceding siblings ...)
  2023-05-14  1:30 ` jvdelisle at gcc dot gnu.org
@ 2023-05-14  3:34 ` jvdelisle at gcc dot gnu.org
  2024-02-17  0:26 ` jvdelisle at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2023-05-14  3:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
In list_read.c we have this comment:

/* To read a logical we have to look ahead in the input stream to make sure
    there is not an equal sign indicating a variable name.  To do this we use
    line_buffer to point to a temporary buffer, pushing characters there for
    possible later reading. */

I remember creating this line_buffer for the purpose. Now to figure out why it
is not working. This was quite a while ago!

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

* [Bug libfortran/107068] Run-time error when reading logical arrays with a namelist
  2022-09-28 13:16 [Bug fortran/107068] New: Run-time error when reading logical arrays with a namelist r.m.potvliege at durham dot ac.uk
                   ` (6 preceding siblings ...)
  2023-05-14  3:34 ` jvdelisle at gcc dot gnu.org
@ 2024-02-17  0:26 ` jvdelisle at gcc dot gnu.org
  2024-02-17 15:35 ` cvs-commit at gcc dot gnu.org
  2024-04-10  2:31 ` jvdelisle at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2024-02-17  0:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
After a bit of sleuthing it turns out that the '(' in the name was being
ignored and the comma in '(1,2)' was being treated as a delimiter.  Since the
following '=' was not seen yet, the 2 was seen as a repeat value and we get the
error.

This is fixed with the following patch:

diff --git a/libgfortran/io/list_read.c b/libgfortran/io/list_read.c
index f8ca64422de..0b7884fdda7 100644
--- a/libgfortran/io/list_read.c
+++ b/libgfortran/io/list_read.c
@@ -888,6 +888,14 @@ read_logical (st_parameter_dt *dtp, int length)
   for(i = 0; i < 63; i++)
     {
       c = next_char (dtp);
+      if (c == '(')
+       {
+         l_push_char (dtp, c);
+         dtp->u.p.nml_read_error = 1;
+         dtp->u.p.line_buffer_enabled = 1;
+         dtp->u.p.line_buffer_pos = 0;
+         return;
+       }
       if (is_separator(c))
        {
          /* All done if this is not a namelist read.  */

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

* [Bug libfortran/107068] Run-time error when reading logical arrays with a namelist
  2022-09-28 13:16 [Bug fortran/107068] New: Run-time error when reading logical arrays with a namelist r.m.potvliege at durham dot ac.uk
                   ` (7 preceding siblings ...)
  2024-02-17  0:26 ` jvdelisle at gcc dot gnu.org
@ 2024-02-17 15:35 ` cvs-commit at gcc dot gnu.org
  2024-04-10  2:31 ` jvdelisle at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-17 15:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jerry DeLisle <jvdelisle@gcc.gnu.org>:

https://gcc.gnu.org/g:fccfe6625121512f247cb59888e50eb9dcc84409

commit r14-9048-gfccfe6625121512f247cb59888e50eb9dcc84409
Author: Jerry DeLisle <jvdelisle@gcc.gnu.org>
Date:   Fri Feb 16 17:06:37 2024 -0800

    libgfortran: Fix namelist read.

            PR libfortran/107068

    libgfortran/ChangeLog:

            * io/list_read.c (read_logical): When looking for a possible
            variable name, check for left paren, indicating a possible
            array reference.

    gcc/testsuite/ChangeLog:

            * gfortran.dg/pr107068.f90: New test.

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

* [Bug libfortran/107068] Run-time error when reading logical arrays with a namelist
  2022-09-28 13:16 [Bug fortran/107068] New: Run-time error when reading logical arrays with a namelist r.m.potvliege at durham dot ac.uk
                   ` (8 preceding siblings ...)
  2024-02-17 15:35 ` cvs-commit at gcc dot gnu.org
@ 2024-04-10  2:31 ` jvdelisle at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2024-04-10  2:31 UTC (permalink / raw)
  To: gcc-bugs

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

Jerry DeLisle <jvdelisle at gcc dot gnu.org> changed:

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

--- Comment #10 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
Fixed on trunk. Closing.

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

end of thread, other threads:[~2024-04-10  2:31 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-28 13:16 [Bug fortran/107068] New: Run-time error when reading logical arrays with a namelist r.m.potvliege at durham dot ac.uk
2022-09-28 13:28 ` [Bug fortran/107068] " r.m.potvliege at durham dot ac.uk
2022-09-28 18:23 ` [Bug libfortran/107068] " anlauf at gcc dot gnu.org
2022-09-28 20:25 ` r.m.potvliege at durham dot ac.uk
2022-09-28 20:26 ` r.m.potvliege at durham dot ac.uk
2023-05-13 19:44 ` jvdelisle at gcc dot gnu.org
2023-05-14  1:30 ` jvdelisle at gcc dot gnu.org
2023-05-14  3:34 ` jvdelisle at gcc dot gnu.org
2024-02-17  0:26 ` jvdelisle at gcc dot gnu.org
2024-02-17 15:35 ` cvs-commit at gcc dot gnu.org
2024-04-10  2:31 ` jvdelisle 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).