Bug 33152 - Initialization/declaration problems in block data
Summary: Initialization/declaration problems in block data
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.1.3
: P3 normal
Target Milestone: ---
Assignee: Jerry DeLisle
URL:
Keywords: accepts-invalid, ice-on-invalid-code, rejects-valid
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2007-08-22 22:34 UTC by Thomas Ruedas
Modified: 2007-11-25 23:51 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-11-25 03:28:44


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Ruedas 2007-08-22 22:34:18 UTC
The following four variants of declarations have been tried in a block 
 data statement with gfortran 4.1.3 and partly also with 4.3.0: 
 Var. 1: 
 character(len=3) :: emname(nmin)=(/'bar','baz'/) 
 common/nmstr/emname 
 gives this error: 
  In file test.f90:16 
 common/nmstr/emname 
                   1 
 Error: Previously initialized symbol 'emname' in COMMON block 'nmstr' 
 at (1) 
 
Var. 2: 
 common/nmstr/emname 
 character(len=3) :: emname(nmin)=(/'bar','baz'/) 
 gives this error: 
  In file test.f90:19 
 character(len=3) :: emname(nmin)=(/'bar','baz'/) 
                                                1 
 Error: Initializer not allowed for COMMON variable 'emname' at (1) 
  In file test.f90:16 
 common/nmstr/emname 
                   1 
 Error: Symbol 'emname' at (1) has no IMPLICIT type 
 
Var. 3: 
 common/nmstr/emname 
 data emname/'bar','baz'/ 
 character(len=3) :: emname(nmin) 
 
gives this error: 
 test.f90:1: internal compiler error: in check_data_variable, at 
 fortran/resolve.c:5865 
 Please submit a full bug report, 
 with preprocessed source if appropriate. 
 
Var. 4: 
 character(len=3) :: emname(nmin) !=(/'bar','baz'/) 
 common/nmstr/emname 
 data emname/'bar','baz'/ 
 
works. 
My question is this: I thought all four variants are compliant with the standard. Which ones are possibly not, and where does gfortran indeed have a bug? Var. 1 worked with the Intel compiler; I didn't/can't test the others. The complete test program is below (comment/uncomment some lines as applicable). My system is SUSE Linux 10.2.
 
program foo 
 implicit none 
 integer, parameter :: nmin=2 
 double precision :: rho0(nmin) 
 common/phasedat/rho0 
 
end program foo 
 
block data thdinit 
 implicit none 
 integer, parameter :: nmin=2 
 !double precision :: rho0(nmin) 
 common/phasedat/rho0 
 double precision :: rho0(nmin) 
 character(len=3) :: emname(nmin) !=(/'bar','baz'/) 
 common/nmstr/emname 
 data emname/'bar','baz'/ 
 !character(len=3) :: emname(nmin)=(/'bar','baz'/) 
 end block data thdinit
Comment 1 kargl 2007-08-23 00:09:41 UTC
It's much worse than you've indicated. :(

gfortran compiles 

  subroutine y
  data emname/'bar'/
  character(len=3) :: emname
  end subroutine y

which violates "A variable that appears in a DATA statement and has not
been typed previously may appear in a subsequent type declaration only if
that declaration confirms the implicit typing."  See 5.2.10.

The ICE in your Var. 3 occurs in this simplified code

  subroutine z
  integer, parameter :: nmin=2
  data emname/'bar','baz'/
  character(len=3) :: emname(nmin)
  end subroutine z

so the fact that we've changed to an array of strings isn't
handled correctly.  I think an error should occur here because
"An array name, array section, or array element that appears in a
DATA statement shall have had its array properties established by
a previous specification statement." See 5.2.10. That is, the order
of the statements is wrong.

Your variations 1 and 2 should be legal via 5.5.2.4(3): "A data object
in a named common block may be initially defined by means of a DATA
statement or type declaration statement in a block data program unit 
(11.4), but objects in blank common shall not be initially defined."

It seems gfortran is ignoring the "block data program unit" part of
the above.





Comment 2 Paul Thomas 2007-10-21 07:30:20 UTC
Given Steve's comment, this clearly should be confirmed!

Paul
Comment 3 Joost VandeVondele 2007-10-22 07:03:41 UTC
Just to be sure, it is a rejects-valid as well.

BLOCK DATA
 character(len=3) :: emname(2)=(/'bar','baz'/)
 common/nmstr/emname
END BLOCK DATA
END
Comment 4 Jerry DeLisle 2007-11-25 03:28:44 UTC
I have a patch on its way.
Comment 5 Jerry DeLisle 2007-11-25 15:58:02 UTC
Subject: Bug 33152

Author: jvdelisle
Date: Sun Nov 25 15:57:55 2007
New Revision: 130409

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130409
Log:
2007-11-25  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/33152
	* gfortran.texi: Document default forms assumed for various file
	extensions.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/gfortran.texi

Comment 6 Jerry DeLisle 2007-11-25 17:22:03 UTC
oops, I had the wrong PR number in the ChangeLog. Should have been for PR34175.
Comment 7 Jerry DeLisle 2007-11-25 22:12:26 UTC
Subject: Bug 33152

Author: jvdelisle
Date: Sun Nov 25 22:12:19 2007
New Revision: 130415

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130415
Log:
2007-11-25  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/33152
	* decl.c (add_init_expr_to_sym): Remove error message.
	* resolve.c (check_data_variable): Add new check for a data variable
	that has an array spec, but no ref and issue an error.
	* match.c (gfc_match_common): Remove error message.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/match.c
    trunk/gcc/fortran/resolve.c

Comment 8 Jerry DeLisle 2007-11-25 22:15:04 UTC
Subject: Bug 33152

Author: jvdelisle
Date: Sun Nov 25 22:14:57 2007
New Revision: 130416

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130416
Log:
2007-11-25  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/33152
	*gfortran.dg\blockdata_4.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/blockdata_4.f90
Modified:
    trunk/gcc/testsuite/ChangeLog

Comment 9 Jerry DeLisle 2007-11-25 23:51:43 UTC
Fixed on trunk.