Bug 23232

Summary: [4.1 only] DATA implied DO variables
Product: gcc Reporter: Roger Ferrer Ibáñez <rofi>
Component: fortranAssignee: Paul Thomas <pault>
Status: RESOLVED FIXED    
Severity: normal CC: federico.carminati, fxcoudert, gcc-bugs, happydeer
Priority: P2 Keywords: rejects-valid
Version: unknown   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2007-01-04 15:46:52
Bug Depends on:    
Bug Blocks: 19292, 29395    
Attachments: Failing case with an optional commented checking part

Description Roger Ferrer Ibáñez 2005-08-04 15:58:29 UTC
gcc version 4.1.0 20050730 (experimental)

The following two DATA statements are rejected by gfortran because "J" is not
considered a valid primary in those expressions although it is the variable of
another enclosing data-implied-do.

 PROGRAM p
  REAL :: ONE_ARRAY(100, 100)
  INTEGER :: K, J

  DATA ((ONE_ARRAY (K, J), K = 1, J-1), J = 1, 100) /4950 * 1.0/
  DATA ((ONE_ARRAY (K, J), K = J, 100), J = 1, 100) /5050 * 0.0/
 END PROGRAM

$ gfortran -fsyntax-only snippet.f90
 In file snippet.f90:5

  DATA ((ONE_ARRAY (K, J), K = 1, J-1), J = 1, 100) /4950 * 1.0/
                                1
Error: Variable 'j' at (1) cannot appear in an initialization expression
 In file snippet.f90:6

  DATA ((ONE_ARRAY (K, J), K = J, 100), J = 1, 100) /5050 * 0.0/
                             1
Error: Variable 'j' at (1) cannot appear in an initialization expression
Comment 1 Roger Ferrer Ibáñez 2005-08-04 15:59:54 UTC
Created attachment 9431 [details]
Failing case with an optional commented checking part
Comment 2 Tobias Schlüter 2005-08-16 19:20:35 UTC
Confirmed g77. g77 accepts similar code.
Comment 3 Andrew Pinski 2005-09-28 13:24:05 UTC
*** Bug 24100 has been marked as a duplicate of this bug. ***
Comment 4 Francois-Xavier Coudert 2006-10-08 21:59:20 UTC
*** Bug 29395 has been marked as a duplicate of this bug. ***
Comment 5 Francois-Xavier Coudert 2006-10-08 21:59:43 UTC
(In reply to comment #4)
> *** Bug 29395 has been marked as a duplicate of this bug. ***

$ cat a10.f90 
  integer :: i(2,2)
  data ((i(k,j), j = 1, k), k = 1, 2) / 3 * 0 / 
  end 
$ gfortran a10.f90 
 In file a10.f90:2

  data ((i(k,j), j = 1, k), k = 1, 2) / 3 * 0 / 
                      1
Error: Parameter 'k' at (1) has not been declared or is a variable, which does
not reduce to a constant expression
Comment 6 happydeer 2006-10-24 14:05:32 UTC
Fortran runtime error: Bad real number in item 1 of list input




My READ statement is:
READ(2,*)(JM(I,IQ),IQ=0,MQ)

JM(I,IQ) got from an input file.

JM(I,IQ) defined :DOUBLE PRECISION JM(NSDMAX,0:MQ),JB(0:LMAX,0:MB)

I don't know if this is enough?
Comment 7 patchapp@dberlin.org 2007-01-04 15:35:26 UTC
Subject: Bug number PR23232

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/2007-01/msg00239.html
Comment 8 Paul Thomas 2007-01-04 15:46:52 UTC
I have just submitted a patch.

Paul
Comment 9 Paul Thomas 2007-01-05 14:45:46 UTC
Subject: Bug 23232

Author: pault
Date: Fri Jan  5 14:45:20 2007
New Revision: 120485

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=120485
Log:
2007-01-05  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/23232
	* decl.c (gfc_in_match_data, gfc_set_in_match_data): New
	functions to signal that a DATA statement is being matched.
	(gfc_match_data): Call gfc_set_in_match_data on entry and on
	exit.
	* gfortran.h : Add prototypes for above.
	* expr.c (check_init_expr): Avoid check on parameter or
	variable if gfc_in_match_data is true.
	(gfc_match_init_expr): Do not call error on non-reduction of
	expression if gfc_in_match_data is true.

	PR fortran/27996
	PR fortran/27998
	* decl.c (gfc_set_constant_character_len): Add boolean arg to
	flag array constructor resolution.  Warn if string is being
	truncated.  Standard dependent error if string is padded. Set
	new arg to false for all three calls to
	gfc_set_constant_character_len.
	* match.h : Add boolean arg to prototype for
	gfc_set_constant_character_len.
	* gfortran.h : Add warn_character_truncation to gfc_options.
	* options.c (set_Wall): Set warn_character_truncation if -Wall
	is set.
	* resolve.c (resolve_code): Warn if rhs string in character
	assignment has to be truncated.
	* array.c (gfc_resolve_character_array_constructor): Set new
	argument to true for call to gfc_set_constant_character_len.

2007-01-05  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/23232
	* gfortran.dg/data_implied_do_1.f90: New test.

	PR fortran/27996
	PR fortran/27998
	* gfortran.dg/char_length_1.f90: New test.



Added:
    trunk/gcc/testsuite/gfortran.dg/data_implied_do_1.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/array.c
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/match.h
    trunk/gcc/fortran/options.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/char_length_1.f90

Comment 10 Paul Thomas 2007-01-14 14:50:13 UTC
Subject: Bug 23232

Author: pault
Date: Sun Jan 14 14:49:50 2007
New Revision: 120772

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=120772
Log:
2007-01-14  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
	    Paul Thomas  <pault@gcc.gnu.org>

	Back port from trunk

	PR fortran/30408
	* lang.opt: Add Wcharacter_truncation option.
	* options.c (gfc_init_options): Initialize
	gfc_option.warn_character_truncation to zero.
	(gfc_handle_option): Add case for OPT_Wcharacter_truncation.

	PR fortran/30408
	* resolve.c (resolve_code): Use the code->expr character length
	directly to set length of llen.

2007-01-14  Paul Thomas  <pault@gcc.gnu.org>

	Backports from trunk

	PR fortran/23232
	* decl.c (gfc_in_match_data, gfc_set_in_match_data): New
	functions to signal that a DATA statement is being matched.
	(gfc_match_data): Call gfc_set_in_match_data on entry and on
	exit.
	* gfortran.h : Add prototypes for above.
	* expr.c (check_init_expr): Avoid check on parameter or
	variable if gfc_in_match_data is true.
	(gfc_match_init_expr): Do not call error on non-reduction of
	expression if gfc_in_match_data is true.

	PR fortran/27996
	PR fortran/27998
	* decl.c (gfc_set_constant_character_len): Add boolean arg to
	flag array constructor resolution.  Warn if string is being
	truncated.  Standard dependent error if string is padded. Set
	new arg to false for all three calls to
	gfc_set_constant_character_len.
	* match.h : Add boolean arg to prototype for
	gfc_set_constant_character_len.
	* gfortran.h : Add warn_character_truncation to gfc_options.
	* options.c (set_Wall): Set warn_character_truncation if -Wall
	is set.
	* resolve.c (resolve_code): Warn if rhs string in character
	assignment has to be truncated.
	* array.c (gfc_resolve_character_array_constructor): Set new
	argument to true for call to gfc_set_constant_character_len.

	PR fortran/30410
	* trans-decl.c (gfc_sym_mangled_function_id): Module, external
	symbols must not have the module name prepended.

2007-01-14  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/23232
	* gfortran.dg/data_implied_do_1.f90: New test.

	PR fortran/27996
	PR fortran/27998
	* gfortran.dg/char_length_1.f90: New test.

	PR fortran/30410
	* gfortran.dg/external_procedures_2.f90: New test.

Added:
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/char_length_1.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/data_implied_do_1.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/external_procedures_2.f90
Modified:
    branches/gcc-4_2-branch/gcc/fortran/ChangeLog
    branches/gcc-4_2-branch/gcc/fortran/array.c
    branches/gcc-4_2-branch/gcc/fortran/decl.c
    branches/gcc-4_2-branch/gcc/fortran/expr.c
    branches/gcc-4_2-branch/gcc/fortran/gfortran.h
    branches/gcc-4_2-branch/gcc/fortran/lang.opt
    branches/gcc-4_2-branch/gcc/fortran/match.h
    branches/gcc-4_2-branch/gcc/fortran/options.c
    branches/gcc-4_2-branch/gcc/fortran/resolve.c
    branches/gcc-4_2-branch/gcc/fortran/trans-decl.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog

Comment 11 Paul Thomas 2007-01-14 14:51:35 UTC
Fixed on trunk and 4.2

Paul