public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/109099] New: Assignment in NAMELIST input does not fill in row-column order
@ 2023-03-11  4:11 urbanjost at comcast dot net
  2023-03-11 21:30 ` [Bug fortran/109099] " anlauf at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: urbanjost at comcast dot net @ 2023-03-11  4:11 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109099
           Summary: Assignment in NAMELIST input does not fill in
                    row-column order
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: urbanjost at comcast dot net
  Target Milestone: ---

program testit
integer, allocatable :: x(:,:); namelist / group / x
character(len=80) :: input(3)
   allocate( x(3,4),source=999)
   input=[&
   "&group          ",&
   " x(2,3)=1,2,3,4,",&
   "/               "]
   read( input, nml=group)
   write(*,group)
end program testit


gfortran 12.2 generating
 &GROUP X= 7*999 ,1 ,2 ,999 ,3 , 4 , /
should be
 &GROUP X = 7*999, 1, 2, 3, 4, 999 /

The values on the RHS are not stored in row-column order starting at the
specified address, instead they are stored in row-column order till the end of
the column and then continued at the same row as the address instead of the top
row. So if the row of the starting address is one it looks OK. They way I read
the description of NAMELIST group input it should just fill in a contigious
section of values (?)

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

* [Bug fortran/109099] Assignment in NAMELIST input does not fill in row-column order
  2023-03-11  4:11 [Bug fortran/109099] New: Assignment in NAMELIST input does not fill in row-column order urbanjost at comcast dot net
@ 2023-03-11 21:30 ` anlauf at gcc dot gnu.org
  2023-03-12  0:41 ` urbanjost at comcast dot net
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-03-11 21:30 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-03-11

--- Comment #1 from anlauf at gcc dot gnu.org ---
The code gives a runtime error with NAG, and it looks like the example is
invalid. I get:

Runtime Error: Invalid character '2' in NAMELIST input
Program terminated by I/O error on internal file

My interpretation is that NAG thinks that

 x(2,3)=1,2,3,4,

consists of one legal name-value subsequence (i.e. x(2,3)=1), followed by junk.

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

* [Bug fortran/109099] Assignment in NAMELIST input does not fill in row-column order
  2023-03-11  4:11 [Bug fortran/109099] New: Assignment in NAMELIST input does not fill in row-column order urbanjost at comcast dot net
  2023-03-11 21:30 ` [Bug fortran/109099] " anlauf at gcc dot gnu.org
@ 2023-03-12  0:41 ` urbanjost at comcast dot net
  2023-03-12  0:45 ` urbanjost at comcast dot net
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: urbanjost at comcast dot net @ 2023-03-12  0:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from urbanjost at comcast dot net ---
Created attachment 54640
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54640&action=edit
interactive program for trying out NAMELIST group input

This may be an "oops" after all; looks like I have been depending on a
non-standard behavior after reviewing your comment and trying to find in the
standard what should happen. Ends up there is a statement that if the LHS
describes a scalar value the RHS can only have one value that I had not
noticed.

After trying the  attached interactive program with several compilers and
reading the latest version of the Fortran standard, it appears to be an
extension to follow x(2,3)= by more than one value, although so far NAG is the
only one that warns or gives an error per the previous comment (I do not have
access to nagfor(1) currently). 

The correct way to just fill in array order appears to be to use null values
and have the LHS be the array name:

    x=9*,1,2,3

which would start filling on the tenth value regardless of the shape of x,
apparently.  For the case of a vector  x(10:)=1,2,3  would also be defined by
the standard. For multiple dimensions I guess you just have to figure out the
number of null values to use instead of giving a starting "address". 

Thanks for the review, but although I have used this syntax for a very long
time it is apparently (now?) an extension to allow it, so behavior can
legitimately vary.

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

* [Bug fortran/109099] Assignment in NAMELIST input does not fill in row-column order
  2023-03-11  4:11 [Bug fortran/109099] New: Assignment in NAMELIST input does not fill in row-column order urbanjost at comcast dot net
  2023-03-11 21:30 ` [Bug fortran/109099] " anlauf at gcc dot gnu.org
  2023-03-12  0:41 ` urbanjost at comcast dot net
@ 2023-03-12  0:45 ` urbanjost at comcast dot net
  2023-03-12 19:39 ` [Bug libfortran/109099] " anlauf at gcc dot gnu.org
  2023-03-14  1:44 ` jvdelisle at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: urbanjost at comcast dot net @ 2023-03-12  0:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from urbanjost at comcast dot net ---
So I think you are right and this is not standard; so instead of an error
at most it would be nice to get a warning/error message indicating too many
values were used or that an extension is used when the -std flag is used.
If preferable this can be closed; but it would be nice to get a warning/error
like NAG. For backward compatibility I think just a warning is fine myself.

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

* [Bug libfortran/109099] Assignment in NAMELIST input does not fill in row-column order
  2023-03-11  4:11 [Bug fortran/109099] New: Assignment in NAMELIST input does not fill in row-column order urbanjost at comcast dot net
                   ` (2 preceding siblings ...)
  2023-03-12  0:45 ` urbanjost at comcast dot net
@ 2023-03-12 19:39 ` anlauf at gcc dot gnu.org
  2023-03-14  1:44 ` jvdelisle at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-03-12 19:39 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P5
           Severity|normal                      |enhancement
           Keywords|                            |diagnostic
             Status|WAITING                     |NEW
          Component|fortran                     |libfortran

--- Comment #4 from anlauf at gcc dot gnu.org ---
I've checked the behavior with other compilers:

Nvidia 23.1 and Flang:

FIO-F-233/namelist read/internal file/too many constants to initialize group
item.
 In source file pr109099.f90, at line number 9


Crayftn 14.0.0:

 &GROUP  X = 7*999,  1,  2,  3,  4,  999 /


Ifort 2021.8:

 &GROUP
 X       = 7*999,           1,           2,           3,           4,        
999
 /


Changing component to libfortran as this is a missing runtime diagnostic.

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

* [Bug libfortran/109099] Assignment in NAMELIST input does not fill in row-column order
  2023-03-11  4:11 [Bug fortran/109099] New: Assignment in NAMELIST input does not fill in row-column order urbanjost at comcast dot net
                   ` (3 preceding siblings ...)
  2023-03-12 19:39 ` [Bug libfortran/109099] " anlauf at gcc dot gnu.org
@ 2023-03-14  1:44 ` jvdelisle at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2023-03-14  1:44 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #5 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
Well I got curious here as I implemented many of the namelist features and have
not seen too many namelist related bugs.  This is with the example in the
original post.

$ gfc -std=f2003 pr109099.f90 
$ ./a.out 
At line 9 of file pr109099.f90
Fortran runtime error: Cannot match namelist object name 234

My thinking is auto-filling anything is a legacy extension.

Now if one comments out the READ and sees how gfortran writes the namelist:

$ gfc -std=f2003 pr109099.f90 
$ ./a.out 
&GROUP
 X= 12*999        ,
 /

My own thought is that it is always good to check things this way to see if the
"form" of the namelist input is good. Modifying your program:

program testit
integer, allocatable :: x(:,:); namelist / group / x
character(len=80) :: input(3)
   allocate( x(3,4),source=999)
   x = reshape ([999, 999, 999, 999, 999, 999, 1, 2, 3, 4, 999, 999], [3, 4]) 
   print *, shape(x), size(x)
   input=[&
   "&group          ",&
   " x(2,3)=1,2,3,4,",&
   "/               "]
   !read( input, nml=group)
   write(*,group)
end program testit

Assuming I have your intent right in the reshape.

$ ./a.out 
           3           4          12
&GROUP
 X= 6*999        ,1          ,2          ,3          ,4          ,
  2*999        ,
 /

and then doing the following shows a safer way to do these things:

program testit
integer, allocatable :: x(:,:); namelist / group / x
character(len=20) :: input(3)
   allocate( x(3,4),source=999)
   input=["&GROUP            ",&
   " X= 6*999,1,2,3,4,",&
   " 2*999,/          "]
   read( input, nml=group)
   write(*,group)
end program testit

$ gfc -std=f2003 pr109099.f90 
$ ./a.out 
&GROUP
 X= 6*999        ,1          ,2          ,3          ,4          ,
  2*999        ,
 /

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

end of thread, other threads:[~2023-03-14  1:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-11  4:11 [Bug fortran/109099] New: Assignment in NAMELIST input does not fill in row-column order urbanjost at comcast dot net
2023-03-11 21:30 ` [Bug fortran/109099] " anlauf at gcc dot gnu.org
2023-03-12  0:41 ` urbanjost at comcast dot net
2023-03-12  0:45 ` urbanjost at comcast dot net
2023-03-12 19:39 ` [Bug libfortran/109099] " anlauf at gcc dot gnu.org
2023-03-14  1:44 ` 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).