[libgfortran] PR107068 Run-time error when reading logical arrays with a namelist

Message ID 81e691f6-efff-4897-891a-76217cf73c92@gmail.com
State Committed
Commit fccfe6625121512f247cb59888e50eb9dcc84409
Headers
Series [libgfortran] PR107068 Run-time error when reading logical arrays with a namelist |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Testing passed

Commit Message

Jerry D Feb. 17, 2024, 1:40 a.m. UTC
  The attached patch fixes this one. Se the ChangeLog below for explanation.

OK for trunk?

I think simple enough to backport to 13 as well.

Regards,

Jerry

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

     libgfortran: Fix namelist read.

             PR libgfortran/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.
  

Comments

FX Coudert Feb. 17, 2024, 10:24 a.m. UTC | #1
> OK for trunk?
> I think simple enough to backport to 13 as well.

OK, but probably best to wait a few weeks before backporting.

FX
  

Patch

diff --git a/gcc/testsuite/gfortran.dg/pr107068.f90 b/gcc/testsuite/gfortran.dg/pr107068.f90
new file mode 100644
index 00000000000..c5ea0c1d244
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr107068.f90
@@ -0,0 +1,22 @@ 
+! { dg-do run }
+program test
+  implicit none
+  integer :: error
+  logical, dimension(3,3) :: flc,flp
+  namelist/inputdata/flc, flp
+
+  flc = .false.
+  flp = .false.
+
+  open(10, file="inputfile")
+  write(10,*) "&INPUTDATA"
+  write(10,*) " FLC = T, "
+  write(10,*) " FLP(1,2) = T,"
+  write(10,*) "/"
+  rewind(10)
+  !write(*, nml=inputdata)
+  !open(10,file="inputfile")
+  read(10,inputdata,iostat=error)
+  close(10, status='delete')
+  if (error /= 0) stop 20
+end program test
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.  */