Bug 17229 - parser confused by arithmetic if inside an if
Summary: parser confused by arithmetic if inside an if
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.0
Assignee: Francois-Xavier Coudert
URL:
Keywords: patch, rejects-valid
: 18561 20824 (view as bug list)
Depends on:
Blocks: 19292
  Show dependency treegraph
 
Reported: 2004-08-29 15:14 UTC by Bud Davis
Modified: 2005-04-20 02:29 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-04-06 13:52:39


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bud Davis 2004-08-29 15:14:24 UTC
reduced example to demonstrate:

$ cat z.f
      INTEGER INCX
      INTEGER INCY
      IF (INCX.EQ.INCY) IF (INCX-1) 5,20,60
 5    CONTINUE
 20   CONTINUE
 60   CONTINUE
      END
$ gfc z.f
 In file z.f:3
 
      IF (INCX.EQ.INCY) IF (INCX-1) 5,20,60
                       1
Error: Unclassifiable statement in IF-clause at (1)
 In file z.f:4
 
 5    CONTINUE
 1
Warning: Label 5 at (1) defined but not used
 In file z.f:5
 
 20   CONTINUE
  1
Warning: Label 20 at (1) defined but not used
 In file z.f:6
 
 60   CONTINUE
  1
Warning: Label 60 at (1) defined but not used
$ gfc --version
GNU Fortran 95 (GCC 3.5.0 20040829 (experimental))
Copyright (C) 2003 Free Software Foundation, Inc.
 
GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING


works under g77:

$ g77 z.f
Comment 1 Tobias Schlüter 2004-08-29 17:16:45 UTC
The standard has the following (I'm quoting the Fortran 90 standard, I assume
something similar is in F95, but Fortran 90 is the last standard to contain the
arithmetic if statement):

R807 if-stmt is IF (...) action-stmt
Constraint: The action-stmt must not be an if-stmt, end-progranm-stmt, ...

arithmetic-if-stmt and if-then-stmt are not action-stmts. So we rightfully
reject this code and its sibling
if (.true.) if (cond) then
 ...
end if

As a workaround there's .AND., so I don't think this bug should be a priority.
Comment 2 Andrew Pinski 2004-11-19 15:17:07 UTC
*** Bug 18561 has been marked as a duplicate of this bug. ***
Comment 3 Francois-Xavier Coudert 2005-04-06 12:38:31 UTC
But then, some scientific libraries are using it (I was about to report the same
bug when a search pointed to this one). And since it works on any compiler I
could find (including g77), I'd change that into a bug (and not enhancement).
Comment 4 prthomas@drfccad.cea.fr 2005-04-06 13:22:20 UTC
Subject: RE:  parser confused by arithmetic if inside a
	n if


> But then, some scientific libraries are using it (I was about 
> to report the same
> bug when a search pointed to this one). And since it works on 
> any compiler I
> could find (including g77), I'd change that into a bug (and 
> not enhancement).
> 

Neither Tobi not Andrew said that it is not a bug......

Paul
Comment 5 Francois-Xavier Coudert 2005-04-06 13:52:38 UTC
Paul: Before I changed the severity field, it was "enhancement".

All: I was a patch for this one, I will polish the testcase a bit and post it in
a few days.
Comment 6 Francois-Xavier Coudert 2005-04-06 14:57:12 UTC
Patch proposed here: http://gcc.gnu.org/ml/fortran/2005-04/msg00104.html
Comment 7 CVS Commits 2005-04-08 10:57:07 UTC
Subject: Bug 17229

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	fxcoudert@gcc.gnu.org	2005-04-08 10:56:54

Modified files:
	gcc/fortran    : ChangeLog match.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gfortran.dg: pr17229.f 

Log message:
	PR fortran/17229
	
	* match.c (gfc_match_arithmetic_if): New function to match an
	arithmetic IF statement.
	(gfc_match_if): Use gfc_match_arithmetic_if to match an
	arithmetic IF statement embedded in a simple IF statement.
	
	* gfortran.dg/pr17229.f: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.335.2.31&r2=1.335.2.32
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/match.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.31.8.1&r2=1.31.8.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.116&r2=1.5084.2.117
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/pr17229.f.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1

Comment 8 CVS Commits 2005-04-08 10:57:09 UTC
Subject: Bug 17229

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	fxcoudert@gcc.gnu.org	2005-04-08 10:57:00

Modified files:
	gcc/fortran    : ChangeLog match.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gfortran.dg: pr17229.f 

Log message:
	PR fortran/17229
	
	* match.c (gfc_match_arithmetic_if): New function to match an
	arithmetic IF statement.
	(gfc_match_if): Use gfc_match_arithmetic_if to match an
	arithmetic IF statement embedded in a simple IF statement.
	
	* gfortran.dg/pr17229.f: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/ChangeLog.diff?cvsroot=gcc&r1=1.381&r2=1.382
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/match.c.diff?cvsroot=gcc&r1=1.32&r2=1.33
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5303&r2=1.5304
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/pr17229.f.diff?cvsroot=gcc&r1=1.1&r2=1.2

Comment 9 Francois-Xavier Coudert 2005-04-08 11:11:54 UTC
Fixed.
Comment 10 Andrew Pinski 2005-04-08 11:43:45 UTC
*** Bug 20824 has been marked as a duplicate of this bug. ***