Bug 56743 - Namelist bug with comment and no blank
Summary: Namelist bug with comment and no blank
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: ---
Assignee: Jerry DeLisle
URL:
Keywords: wrong-code
Depends on:
Blocks: 56744
  Show dependency treegraph
 
Reported: 2013-03-26 16:20 UTC by janus
Modified: 2015-04-21 16:42 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.1.2, 4.3.4, 4.6.3, 4.7.2, 4.8.0, 4.9.0
Last reconfirmed: 2013-03-26 00:00:00


Attachments
Draft patch (only for read_integer) (352 bytes, text/plain)
2013-03-26 16:57 UTC, Tobias Burnus
Details
Test case - please read comment in the file or comment 4 (887 bytes, text/plain)
2013-03-30 10:47 UTC, Tobias Burnus
Details

Note You need to log in before you can comment on or make changes to this bug.
Description janus 2013-03-26 16:20:07 UTC
Reduced test case (inspired by the one in PR 56660), originally reported by Kai Gallmeister:


integer :: value = 100
namelist /nml/ value

write (*, nml=nml)

open (99, file='nml.dat', status="replace")
write(99,*) "&nml"
write(99,*) "  value=1!11"
write(99,*) "/"

rewind(99)
read (99, nml=nml)
write (*, nml=nml)

close (99, status="delete")

end 



Output with 4.3, 4.7 and trunk (haven't tried other versions):

&NML
 VALUE=        100,
 /
&NML
 VALUE=        100,
 /

Expected output:

&NML
 VALUE=        100,
 /
&NML
 VALUE=          1,
 /


The fact that there is no blank between the number and the comment should not make any difference, right? Unfortunately it does ...
Comment 1 Dominique d'Humieres 2013-03-26 16:27:26 UTC
Confirmed.
Comment 2 Tobias Burnus 2013-03-26 16:57:53 UTC
Created attachment 29734 [details]
Draft patch (only for read_integer)

Draft patch - fixes the issue of the test case, but one probably should do an audit of the whole file (list_read). For instance, using REAL instead of INTEGER in the test case also fails. One probably does not need to handle all CASE_SEPARATORS, but presumably a large number of those.
Comment 3 Jerry DeLisle 2013-03-30 04:08:19 UTC
Agree, we should just audit list_read.c for this case.
Comment 4 Tobias Burnus 2013-03-30 10:47:30 UTC
Created attachment 29752 [details]
Test case  - please read comment in the file or comment 4

The test case is successful with ifort 13.1, it fails (iostat/=0, run time failure) with Crayftn and PGI already for "i=1!".


According to the Fortran standard, the example - as the example in comment 0 - is invalid. From Fortran 2008, "10.11.3.6 Namelist comments":

"Except within a character literal constant, a "!" character after a value separator or in the first nonblank position of a namelist input record initiates a comment."

Note the "after a value separator". In "i=1!" there is no value separator after the value "1".


For my character example "c1 = a": Also that example is invalid according to the Fortran standard, which states in "10.11.3.3 Namelist input values":

"When the next effective item is of type character, the input form consists of a delimited sequence of zero or more rep-chars [...]"

Thus, either " or ' is required as delimiter - but the example doesn't use neither.



EXPECTED RESULTS:

(a) "i=1!" is either accepted as vendor extension as "i=1 !...", matching Intel's result.  Or it is rejected with a compile-time error as Crayftn and PGI do it.

Currently, integers and reals (except for INF/NAN) give not error but the result is not modified (BUG!).  For logical, complex and delimited character strings, the value is read (as vendor extension), and for INF and NAN a "cannot match namelist object" error is shown - which is acceptable according to the standard an matches PGI/Crayftn.


(b) For nondelimited character strings: Currently, it gives the error "Cannot match namelist object", which is fine according to the standard. One could still consider to support reading it as vendor extension - as Intel does. (Simply read from the first nonspace character to the first value separator.)
Comment 5 Jerry DeLisle 2013-05-03 20:32:51 UTC
I have a patch testing that fixes the items identified in the attachment of Comment #4 by accepting them as extension.
Comment 6 Jerry DeLisle 2015-04-07 19:28:24 UTC
I forgot about this one.
Comment 7 Jerry DeLisle 2015-04-16 02:23:29 UTC
Potential simple patch.

Index: io/list_read.c
===================================================================
--- io/list_read.c	(revision 222110)
+++ io/list_read.c	(working copy)
@@ -53,7 +53,7 @@ typedef unsigned char uchar;
                       case '5': case '6': case '7': case '8': case '9'
 
 #define CASE_SEPARATORS  case ' ': case ',': case '/': case '\n': case '\t': \
-                         case '\r': case ';'
+                         case '\r': case ';': case '!'
 
 /* This macro assumes that we're operating on a variable.  */
Comment 8 Jerry DeLisle 2015-04-21 16:14:26 UTC
Author: jvdelisle
Date: Tue Apr 21 16:13:54 2015
New Revision: 222271

URL: https://gcc.gnu.org/viewcvs?rev=222271&root=gcc&view=rev
Log:
2015-04-21 Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/56743
	* io/list_read.c (CASE_SEPARATORS): Add case for '!'.
	(is_separator): Add condition for '!'.
	(eat_separator): Use notify_std to warn or errord if '!' is
	encountered before a proper separator.

Modified:
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/io/list_read.c
Comment 9 Jerry DeLisle 2015-04-21 16:33:58 UTC
Author: jvdelisle
Date: Tue Apr 21 16:33:27 2015
New Revision: 222272

URL: https://gcc.gnu.org/viewcvs?rev=222272&root=gcc&view=rev
Log:
2015-04-21 Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/56743
	* gfortran.dg/namelist_87.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/namelist_87.f90
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 10 Jerry DeLisle 2015-04-21 16:42:42 UTC
Fixed on trunk. Closing.