This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch,fortran] Fix keyword check for specifiers (PR29452)
- From: Tobias Burnus <burnus at net-b dot de>
- Cc: "'fortran at gcc dot gnu dot org'" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 27 Oct 2006 12:01:51 +0200
- Subject: Re: [patch,fortran] Fix keyword check for specifiers (PR29452)
- References: <45406FBF.7080102@net-b.de>
Hi,
I also fixed here the dg-error pattern matching.
Tobias Burnus wrote:
> this patch fixes some problems with the string comparisons for the
> argument checks:
>
> - In libgfortran, the "YES"/"NO" etc. checks where only checking whether
> the first (length of fortran string) characters match. That way (Fortran
> string) "N" matched (C string) "NO" etc.
>
> - In the write/read check section of io.c, the advance argument was
> compared against "YE" and "NO", thus "NOT", "YET","Yessica", etc. also
> matches. As we have C strings, I replaced the str-n-casecmp( . , . , 2)
> by strcasecmp.
>
> I didn't use compare_to_allowed_values as the "not_no" is also used for
> other checks (EOR and SIZE). When the missing 7 specifiers with keywords
> are added, one can consider changing also this test to use
> compare_to_allowed_values.
>
> Tobias
>
>
> 2006-10-26 Tobias Burnus <burnus@net-b.de>
>
> PR fortran/29452
> * io.c (check_io_constraints): Fix keyword string comparison.
>
> 2006-10-26 Tobias Burnus <burnus@net-b.de>
>
> PR fortran/29452
> * runtime/string.c (compare0): Check whether string lengths match.
>
> 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.
>
Build (make distclean; ...; make) & "make -k check" tested on
x86_64-unknown-linux-gnu
(Only FAILs are in gcc.c-torture/execute/mayalias-2.c (ICE) and
gcc.dg/tree-ssa/loadpre1*.c
and the XPASSes for gfortran.dg/csqrt_2.f)
Tobias
Index: gcc/fortran/io.c
===================================================================
--- gcc/fortran/io.c (Revision 118080)
+++ gcc/fortran/io.c (Arbeitskopie)
@@ -2697,8 +2701,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
{
Index: libgfortran/runtime/string.c
===================================================================
--- libgfortran/runtime/string.c (Revision 118080)
+++ libgfortran/runtime/string.c (Arbeitskopie)
@@ -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;
}
--- /dev/null 2006-10-21 23:34:46.000000000 +0200
+++ gcc/testsuite/gfortran.dg/write_check.f90 2006-10-27 01:11:11.000000000 +0200
@@ -0,0 +1,16 @@
+! { dg-do run }
+! { dg-shouldfail "Compile-time specifier checking" }
+! Check keyword checking for specifiers
+! PR fortran/29452
+program test
+ implicit none
+ character(len=5) :: str
+ str = 'yes'
+ write(*,'(a)',advance=str) ''
+ str = 'no'
+ write(*,'(a)',advance=str) ''
+ str = 'NOT'
+ write(*,'(a)',advance=str) ''
+end program test
+! { dg-output "At line 13 of file.*" }
+! { dg-output "Bad ADVANCE parameter in data transfer statement" }
--- /dev/null 2006-10-21 23:34:46.000000000 +0200
+++ gcc/testsuite/gfortran.dg/write_check2.f90 2006-10-27 01:05:11.000000000 +0200
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! Check keyword checking for specifiers
+! PR fortran/29452
+ character(len=20) :: str
+ write(13,'(a)',advance='yes') 'Hello:'
+ write(13,'(a)',advance='no') 'Hello:'
+ write(13,'(a)',advance='y') 'Hello:' ! { dg-error "ADVANCE=specifier at \\(1\\) must have value = YES or NO." }
+ write(13,'(a)',advance='yet') 'Hello:' ! { dg-error "ADVANCE=specifier at \\(1\\) must have value = YES or NO." }
+ write(13,'(a)',advance='yess') 'Hello:' ! { dg-error "ADVANCE=specifier at \\(1\\) must have value = YES or NO." }
+ end