Bug 25073 - CASEs overlap
Summary: CASEs overlap
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-26 17:55 UTC by Joost VandeVondele
Modified: 2006-06-25 18:11 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-05-05 21:47:50


Attachments
A patch to fix the PR. (545 bytes, patch)
2006-06-22 14:25 UTC, Paul Thomas
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joost VandeVondele 2005-11-26 17:55:35 UTC
using GNU Fortran 95 (GCC) 4.1.0 20051126 (prerelease)  with '-g -pedantic -std=f95', I get a bad / no diagnostic for the following invalid code:

LOGICAL :: L
SELECT CASE(L)
CASE(.true.)
CASE(.false.)
CASE(.true.)
END SELECT
END
Comment 1 Francois-Xavier Coudert 2005-11-26 19:54:13 UTC
gfortran doesn't detect that the CASEs overlap.

## g95 ##
In file foo.f90:3

CASE(.true.)
     1
In file foo.f90:5

CASE(.true.)
     2
Error: CASEs at (1) and (2) overlap
## Intel ##
fortcom: Error: foo.f90, line 5: This case-value or case-value-range matches a case-value in another case-value-range within the same case-construct.
CASE(.true.)
-----^
compilation aborted for foo.f90 (code 1)
## Portland ##
PGF90-S-0310-Duplicate case value  (foo.f90: 5)
  0 inform,   0 warnings,   1 severes, 0 fatal for MAIN
## Sun ##

CASE(.true.)
     ^
"foo.f90", Line = 5, Column = 6: ERROR: The case value has the same value as a case value on line 3.
Comment 2 Andrew Pinski 2006-02-26 19:49:43 UTC
We do get a warning:
 In file t.f90:2

SELECT CASE(L)
             1
Warning: Logical SELECT CASE block at (1) has more that two cases
Comment 3 Thomas Koenig 2006-04-17 19:38:51 UTC
This is now fixed on mainline and 4.1:

$ cat case.f90
program main
  logical :: l
  select case (l)
  case (.true.)
  case (.true.)
  end select
end program main
$ gfortran case.f90
 In file case.f90:4

  case (.true.)
       1
 In file case.f90:5

  case (.true.)
       2
Error: CASE label at (1) overlaps with CASE label at (2)
$ gfortran -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../../gcc/trunk/configure --prefix=/home/ig25 --enable-languages=c,fortran
Thread model: posix
gcc version 4.2.0 20060412 (experimental)

All we need now is a test case, then we can close this.
Comment 4 Francois-Xavier Coudert 2006-05-05 21:47:49 UTC
I'll commit a testcase when I find some time this week-end...
Comment 5 Francois-Xavier Coudert 2006-05-08 09:48:53 UTC
Humpf, I created a testcase for inclusion in the testsuite, but it reveals that overlap of logical cases is not detected when they're separated from each other:

  select case (l)
  case (.true.)
  case (.false.)
  case (.true.)
  end select

In this case, the overlap is not detected. The "same" code works fine with integer or character variables, and I'm not sure why logicals are a special case.

Thomas, can you give it a try since you designed the original patch?
Comment 6 Thomas Koenig 2006-05-08 22:15:40 UTC
> Thomas, can you give it a try since you designed the original patch?

Actually, I didn't; I completely missed the original test case,
checked this with my own (which didn't expose the error) and
then rashly concluded that this was indeed fixed.  Sorry.

I'll have a look at this, though.

Comment 7 Thomas Koenig 2006-05-31 21:10:04 UTC
This is a real bug, and not an issue of a missing
test case.
Comment 8 Paul Thomas 2006-06-22 14:25:59 UTC
Created attachment 11728 [details]
A patch to fix the PR.

A straightforward fix in resolve.c (resolve_select).

Paul
Comment 9 Paul Thomas 2006-06-22 14:31:02 UTC
> A straightforward fix in resolve.c (resolve_select).

In checking the attachment, I have just seen that the if condition can be simplified to

	      if (cp->low->value.logical & seen_logical)
		{
		  gfc_error ("constant logical value in CASE statement "
			     "is repeated at %L",
			     &cp->low->where);
		  t = FAILURE;
		  break;
		}
	      seen_logical |= cp->low->value.logical == 0 ? 2 : 1;

Paul

Comment 10 Paul Thomas 2006-06-25 15:11:31 UTC
Subject: Bug 25073

Author: pault
Date: Sun Jun 25 15:11:02 2006
New Revision: 114987

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114987
Log:
2006-06-25  Paul Thomas  <pault@gcc.gnu.org>
 
	PR fortran/25056
	* interface.c (compare_actual_formal): Signal an error if the formal
	argument is a pure procedure and the actual is not pure.

	PR fortran/27554
	* resolve.c (resolve_actual_arglist): If the type of procedure
	passed as an actual argument is not already declared, see if it is
	an intrinsic.

	PR fortran/25073
	* resolve.c (resolve_select): Use bits 1 and 2 of a new int to
	keep track of  the appearance of constant logical case expressions.
	Signal an error is either value appears more than once.

	PR fortran/20874
	* resolve.c (resolve_fl_procedure): Signal an error if an elemental
	function is not scalar valued.

	PR fortran/20867
	* match.c (recursive_stmt_fcn): Perform implicit typing of variables.

	PR fortran/22038
	* match.c (match_forall_iterator): Mark new variables as
	FL_UNKNOWN if the match fails.

	PR fortran/28119
	* match.c (gfc_match_forall): Remove extraneous call to
	gfc_match_eos.

	PR fortran/25072
	* resolve.c (resolve_code, resolve_function): Rework
	forall_flag scheme so that it is set and has a value of
	2, when the code->expr (ie. the forall mask) is resolved.
	This is used to change "block" to "mask" in the non-PURE
	error message.


2006-06-25  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/20867
	* gfortran.dg/stfunc_3.f90: New test.

	PR fortran/25056
	* gfortran.dg/impure_actual_1.f90: New test.

	PR fortran/20874
	* gfortran.dg/elemental_result_1.f90: New test.

	PR fortran/25073
	* gfortran.dg/select_7.f90: New test.

	PR fortran/27554
	* intrinsic_actual_1.f: New test.

	PR fortran/22038
	PR fortran/28119
	* gfortran.dg/forall_4.f90: New test.

	PR fortran/25072
	* gfortran.dg/forall_5.f90: New test.



Added:
    trunk/gcc/testsuite/gfortran.dg/elemental_result_1.f90
    trunk/gcc/testsuite/gfortran.dg/forall_4.f90
    trunk/gcc/testsuite/gfortran.dg/forall_5.f90
    trunk/gcc/testsuite/gfortran.dg/impure_actual_1.f90
    trunk/gcc/testsuite/gfortran.dg/intrinsic_actual_1.f
    trunk/gcc/testsuite/gfortran.dg/select_7.f90
    trunk/gcc/testsuite/gfortran.dg/stfunc_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/interface.c
    trunk/gcc/fortran/match.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog

Comment 11 Paul Thomas 2006-06-25 18:08:40 UTC
Subject: Bug 25073

Author: pault
Date: Sun Jun 25 18:08:13 2006
New Revision: 114994

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114994
Log:
2006-06-25  Paul Thomas  <pault@gcc.gnu.org>
 
	PR fortran/25056
	* interface.c (compare_actual_formal): Signal an error if the formal
	argument is a pure procedure and the actual is not pure.

	PR fortran/27554
	* resolve.c (resolve_actual_arglist): If the type of procedure
	passed as an actual argument is not already declared, see if it is
	an intrinsic.

	PR fortran/25073
	* resolve.c (resolve_select): Use bits 1 and 2 of a new int to
	keep track of  the appearance of constant logical case expressions.
	Signal an error is either value appears more than once.

	PR fortran/20874
	* resolve.c (resolve_fl_procedure): Signal an error if an elemental
	function is not scalar valued.

	PR fortran/20867
	* match.c (recursive_stmt_fcn): Perform implicit typing of variables.

	PR fortran/22038
	* match.c (match_forall_iterator): Mark new variables as
	FL_UNKNOWN if the match fails.

	PR fortran/28119
	* match.c (gfc_match_forall): Remove extraneous call to
	gfc_match_eos.

	PR fortran/25072
	* resolve.c (resolve_code, resolve_function): Rework
	forall_flag scheme so that it is set and has a value of
	2, when the code->expr (ie. the forall mask) is resolved.
	This is used to change "block" to "mask" in the non-PURE
	error message.


2006-06-25  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/20867
	* gfortran.dg/stfunc_3.f90: New test.

	PR fortran/25056
	* gfortran.dg/impure_actual_1.f90: New test.

	PR fortran/20874
	* gfortran.dg/elemental_result_1.f90: New test.

	PR fortran/25073
	* gfortran.dg/select_7.f90: New test.

	PR fortran/27554
	* intrinsic_actual_1.f: New test.

	PR fortran/22038
	PR fortran/28119
	* gfortran.dg/forall_4.f90: New test.

	PR fortran/25072
	* gfortran.dg/forall_5.f90: New test.



Added:
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/elemental_result_1.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/forall_4.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/forall_5.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/impure_actual_1.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/intrinsic_actual_1.f
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/select_7.f90
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/stfunc_3.f90
Modified:
    branches/gcc-4_1-branch/gcc/fortran/ChangeLog
    branches/gcc-4_1-branch/gcc/fortran/interface.c
    branches/gcc-4_1-branch/gcc/fortran/match.c
    branches/gcc-4_1-branch/gcc/fortran/resolve.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog

Comment 12 Paul Thomas 2006-06-25 18:11:34 UTC
Fixed on trunk and 4.1

Paul