http://gcc.gnu.org/ml/fortran/2006-10/msg00241.html adds compile-time checking for the specifier arguments of CLOSE and OPEN. This should be done analogously for (cf. 9.5.1 in Fortran 2003) WRITE/READ (some only in READ allowed; some sre not yet implemented in gfortran): - ADVANCE: 'YES', 'NO' - ASYNCHRONOUS: 'YES', 'NO' - BLANK: 'NULL', 'ZERO' - DECIMAL: 'COMMA', 'POINT' - DELIM: 'APOSTROPHE', 'QUOTE', 'NONE - PAD: 'YES', 'NO' - ROUND: 'UP', 'DOWN', 'ZERO', 'NEAREST', 'COMPATIBLE'. 'PROCESSOR_DEFINED' - SIGN: PLUS, SUPPRESS, PROCESSOR_DEFINED
Some tests show: open(13,file='foo',form='format') close(13,status='del') compiles and runs in gfortran. Expected: - A run-time error is shown. - A compile-time-error is shown (probably fixed by FX patch, not checked) * * * write(13,'(a)',advance='N') 'Hello:' This gives a compile-time error, whereas str = 'N' write(13,'(a)',advance=str) 'Hello:' gives not a run-time error. write(13,'(a)',advance='Not') 'Hello:' gives no compile-time error, but a run-time error.
The library problems are due to an error in the string comparison; one only compares the first (fortran string length) characters, but never checks whether the strings are of identical length. Patch: Index: libgfortran/runtime/string.c =================================================================== --- libgfortran/runtime/string.c (revision 117796) +++ libgfortran/runtime/string.c (working copy) @@ -44,6 +44,7 @@ /* Strip trailing blanks from the Fortran string. */ len = fstrlen (s1, s1_len); + if(len != strlen(s2)) return 0; /* don't match */ return strncasecmp (s1, s2, len) == 0; } Similarly for WRITE(*,*,ADVANCE='YES/NO'): Index: gcc/fortran/io.c =================================================================== --- gcc/fortran/io.c (revision 117796) +++ gcc/fortran/io.c (working copy) @@ -2697,8 +2697,8 @@ if (expr->expr_type == EXPR_CONSTANT && expr->ts.type == BT_CHARACTER) { const char * advance = expr->value.character.string; - not_no = strncasecmp (advance, "no", 2) != 0; - not_yes = strncasecmp (advance, "yes", 2) != 0; + not_no = strcasecmp (advance, "no") != 0; + not_yes = strcasecmp (advance, "yes") != 0; } else { I will submit a patch in the next days. (The other suggested checks for READ/WRITE are not yet needed as those options are not supported, yet. I don't know in how far strcasencmp problems occurre at other places as well.)
(In reply to comment #1) > - A compile-time-error is shown (probably fixed by FX patch, not checked) Yes, it's fixed by my patch. Confirming this bug. Tobias, if you want to submit a global patch to resolve these issues (both compile-time and run-time), I'll be happy to review it. 4.3 is in stage 1, it's time for change! :) PS: for the compile-time checks, you can probably use the compare_to_allowed helper routine I added in my "OPEN/CLOSE checks" patch; most of the work is probably reading both F95 and F2003 to spot the differences.
Subject: Bug number PR29452 A patch for this bug has been added to the patch tracker. The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-10/msg01327.html
Subject: Bug 29452 Author: burnus Date: Mon Oct 30 14:17:15 2006 New Revision: 118184 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118184 Log: fortran/ 2006-10-26 Tobias Burnus <burnus@net-b.de> PR fortran/29452 * io.c (check_io_constraints): Fix keyword string comparison. libgfortran/ 2006-10-26 Tobias Burnus <burnus@net-b.de> PR fortran/29452 * runtime/string.c (compare0): Check whether string lengths match. testsuite/ 2006-10-26 Tobias Burnus <burnus@net-b.de> PR fortran/29452 * gfortran.dg/write_check.f90: Check run-time keyword checking. * gfortran.dg/write_check2.f90: Check compile-time keyword checking. Added: branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/write_check.f90 branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/write_check2.f90 Modified: branches/gcc-4_2-branch/gcc/fortran/ChangeLog branches/gcc-4_2-branch/gcc/fortran/io.c branches/gcc-4_2-branch/gcc/testsuite/ChangeLog branches/gcc-4_2-branch/libgfortran/ChangeLog branches/gcc-4_2-branch/libgfortran/runtime/string.c
Accept bug
And mark as fixed. Hopefully, we won't forget to add checks also to the following specifiers as soon as we implement them. WRITE/READ (some only in READ allowed; those are not yet implemented in gfortran): - ASYNCHRONOUS: 'YES', 'NO' - BLANK: 'NULL', 'ZERO' - DECIMAL: 'COMMA', 'POINT' - DELIM: 'APOSTROPHE', 'QUOTE', 'NONE - PAD: 'YES', 'NO' - ROUND: 'UP', 'DOWN', 'ZERO', 'NEAREST', 'COMPATIBLE'. 'PROCESSOR_DEFINED' - SIGN: PLUS, SUPPRESS, PROCESSOR_DEFINED
(In reply to comment #7) > - ASYNCHRONOUS: 'YES', 'NO' > - BLANK: 'NULL', 'ZERO' > - DECIMAL: 'COMMA', 'POINT' > - DELIM: 'APOSTROPHE', 'QUOTE', 'NONE > - PAD: 'YES', 'NO' > - ROUND: 'UP', 'DOWN', 'ZERO', 'NEAREST', 'COMPATIBLE'. 'PROCESSOR_DEFINED' > - SIGN: PLUS, SUPPRESS, PROCESSOR_DEFINED I'm planning to implement those soon. I'll keep that PR open and assigned to me to be sure I remember :)
Subject: Bug 29452 Author: burnus Date: Mon Oct 30 18:22:47 2006 New Revision: 118191 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118191 Log: fortran/ 2006-10-30 Tobias Burnus <burnus@net-b.de> PR fortran/29452 * io.c (check_io_constraints): Fix keyword string comparison. libgfortran/ 2006-10-30 Tobias Burnus <burnus@net-b.de> PR fortran/29452 * runtime/string.c (compare0): Check whether string lengths match. testsuite/ 2006-10-30 Tobias Burnus <burnus@net-b.de> PR fortran/29452 * gfortran.dg/write_check.f90: Check run-time keyword checking. * gfortran.dg/write_check2.f90: Check compile-time keyword checking Added: trunk/gcc/testsuite/gfortran.dg/write_check.f90 trunk/gcc/testsuite/gfortran.dg/write_check2.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/io.c trunk/gcc/testsuite/ChangeLog trunk/libgfortran/ChangeLog trunk/libgfortran/runtime/string.c
I think it's best to close this one. I only wanted to keep it open because I thought I'd add the rest of the F2003 specifiers quickly, which didn't happen.