User account creation filtered due to spam.

Bug 38657 - [4.3 Regression] PUBLIC/PRIVATE Common blocks
Summary: [4.3 Regression] PUBLIC/PRIVATE Common blocks
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.2
: P4 normal
Target Milestone: 4.3.4
Assignee: Paul Thomas
URL:
Keywords: rejects-valid
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2008-12-28 23:07 UTC by Paul Thomas
Modified: 2009-01-26 05:13 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-01-05 17:35:55


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Thomas 2008-12-28 23:07:56 UTC
$cat test3.f90
MODULE TEST3

  PRIVATE

  CHARACTER(LEN=80) :: TESTCHAR
  INTEGER :: TESTINT
  REAL :: TESTREAL

  COMMON /TESTCOMMON1/ TESTCHAR
  COMMON /TESTCOMMON2/ TESTINT
  COMMON /TESTCOMMON3/ TESTREAL

END MODULE TEST3

$cat test2.f90
MODULE TEST2

  USE TEST3

  PRIVATE

  CHARACTER(LEN=80) :: TESTCHAR
  INTEGER :: TESTINT
  REAL :: TESTREAL

  COMMON /TESTCOMMON1/ TESTCHAR
  COMMON /TESTCOMMON2/ TESTINT
  COMMON /TESTCOMMON3/ TESTREAL

  PUBLIC TESTCHAR

END MODULE TEST2

$cat test1.f90
PROGRAM TEST1

  USE TEST2

  WRITE(*,*) TESTCHAR

END PROGRAM TEST1

then when I compile it with gfortran it get the following problem

$gfortran -o test3.o -g -c test3.f90
$gfortran -o test2.o -g -c test2.f90
$gfortran -o test1.o -g -c test1.f90
$gfortran -o test1 -g test1.o test2.o test3.o
test1.o: In function `test1':
/data/test1.f90:6: undefined reference to `__test2_MOD_testchar'
collect2: ld returned 1 exit status
make: *** [test1] Error 1
$ gfortran -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap
--enable-shared --enable-threads=posix --enable-checking=release
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada
--enable-java-awt=gtk --disable-dssi --enable-plugin
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
--enable-libgcj-multifile --enable-java-maintainer-mode
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--disable-libjava-multilib --with-cpu=generic --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.3.2 20081105 (Red Hat 4.3.2-7) (GCC)

If I comment out the USE TEST3 line in test2.f90 then all is fine. The
test code also compiles and links without any problems with the intel
and IBM compilers. Given that everything is private in TEST3 then my
understanding is that it shouldn't matter if TEST2 uses it or not? Is
this a compiler bug or my misunderstanding of the use of COMMON blocks
inside PRIVATE modules? 

Reported in http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/ca3ef24d9bf2afb8#

by Chris Bradley
Comment 1 Tobias Burnus 2009-01-05 13:35:18 UTC
I checked my old trunk builds:

2007-11-05-r129891 - works
2007-11-20-r130310 - fails
(= 25 fortran/ commits)

Assuming no local problems and a clean tree (looks like), the following commit might have caused the regression:

r130257 | fxcoudert | 2007-11-17 14:46:53 +0100 (Sat, 17 Nov 2007) | 6 lines
http://gcc.gnu.org/viewcvs?view=rev&revision=130257

        PR fortran/30285
        * module.c (struct written_common, written_commons): New structure.
        (compare_written_commons, free_written_common, write_common_0):
        New functions.
        (write_common): Call recursive function write_common_0.
Comment 2 Tobias Burnus 2009-01-05 14:18:19 UTC
If one compares the dumps, one finds an additional
  +  extern character(kind=1) testchar[1:80];
in the failing version. Thus while the working version accesses
   &testcommon1.testchar[1]{lb: 1 sz: 1}
the failing uses
   &testchar[1]{lb: 1 sz: 1}

The .mod looks OK though - as far I can see (rearrangements; only one "testcommon1" etc. instead of two).
Comment 3 Mikael Morin 2009-01-05 14:35:50 UTC
(In reply to comment #2)
> The .mod looks OK though - as far I can see (rearrangements; only one
> "testcommon1" etc. instead of two).
> 
The test2.mod is wrong I think.
Without USE TEST3:
[...]
(('testcommon1' 2 0 0 'testcommon1') ('testcommon2' 3 0 0 'testcommon2')
('testcommon3' 4 0 0 'testcommon3'))

()

(2 'testchar' 'test2' 'testchar' 1 ((VARIABLE UNKNOWN-INTENT
UNKNOWN-PROC UNKNOWN UNKNOWN IN_COMMON) (CHARACTER 1 0 0 CHARACTER ((
CONSTANT (INTEGER 4 0 0 INTEGER ()) 0 '80'))) 0 0 () () 0 () () () 0 0)
3 'testint' 'test2' 'testint' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC
UNKNOWN UNKNOWN IN_COMMON) (INTEGER 4 0 0 INTEGER ()) 0 0 () () 0 () ()
() 0 0)
4 'testreal' 'test2' 'testreal' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC
UNKNOWN UNKNOWN IN_COMMON) (REAL 4 0 0 REAL ()) 0 0 () () 0 () () () 0 0)
)

('testchar' 0 2)



With USE TEST3:
[...]
(('testcommon1' 2 0 0 'testcommon1') ('testcommon2' 3 0 0 'testcommon2')
('testcommon3' 4 0 0 'testcommon3'))

()

(5 'testchar' 'test2' 'testchar' 1 ((VARIABLE UNKNOWN-INTENT
UNKNOWN-PROC UNKNOWN UNKNOWN IN_COMMON) (CHARACTER 1 0 0 CHARACTER ((
CONSTANT (INTEGER 4 0 0 INTEGER ()) 0 '80'))) 0 0 () () 0 () () () 0 0)
3 'testint' 'test3' 'testint' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC
UNKNOWN UNKNOWN IN_COMMON) (INTEGER 4 0 0 INTEGER ()) 0 0 () () 0 () ()
() 0 0)
2 'testchar' 'test3' 'testchar' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC
UNKNOWN UNKNOWN IN_COMMON) (CHARACTER 1 0 0 CHARACTER ((CONSTANT (
INTEGER 4 0 0 INTEGER ()) 0 '80'))) 0 0 () () 0 () () () 0 0)
4 'testreal' 'test3' 'testreal' 1 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC
UNKNOWN UNKNOWN IN_COMMON) (REAL 4 0 0 REAL ()) 0 0 () () 0 () () () 0 0)
)

('testchar' 0 5)


With USE TEST3, testreal, testint and testchar are included from module test3, which is wrong because everything is private in test3. We should either have variables from both test2 and test3, or only variables from test2. Furthermore, the 'testcommon1' common refers to 2, which is the wrong testchar (that from test3).
Comment 4 Mikael Morin 2009-01-05 14:47:49 UTC
without USE TEST3, gfc_get_symbol_decl (sym=testchar) returns sym->backend_decl because it is set.
With USE TEST3, sym->backend_decl is not set, and we create the declaration. As testchar is included from test2 we set the assembler name to __test2_MOD_testchar.
Thus the linker message.
Comment 5 Mikael Morin 2009-01-05 14:54:13 UTC
(In reply to comment #4)
> With USE TEST3, sym->backend_decl is not set.
Interestingly, the backend_decl for test3's testchar is set.
Comment 6 Paul Thomas 2009-01-05 16:32:24 UTC
(In reply to comment #1)

> Assuming no local problems and a clean tree (looks like), the following commit
> might have caused the regression:
> 
> r130257 | fxcoudert | 2007-11-17 14:46:53 +0100 (Sat, 17 Nov 2007) | 6 lines
> http://gcc.gnu.org/viewcvs?view=rev&revision=130257
> 
>         PR fortran/30285
>         * module.c (struct written_common, written_commons): New structure.
>         (compare_written_commons, free_written_common, write_common_0):
>         New functions.
>         (write_common): Call recursive function write_common_0.
> 

I have been tinkering with this and have made the above testcase work.  However, legal cases that rename TESTCHAR on USE test3 (with appropriate PUBLIC statements of course) are failing.

I am preparing a large envelope to track what happens to the names.

Paul
Comment 7 Paul Thomas 2009-01-05 17:35:55 UTC
I'm just about to post a patch.

Paul
Comment 8 Paul Thomas 2009-01-05 19:46:17 UTC
Subject: Bug 38657

Author: pault
Date: Mon Jan  5 19:46:06 2009
New Revision: 143090

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

	PR fortran/38657
	* module.c (write_common_0): Use the name of the symtree rather
	than the common block, to determine if the common has been
	written.

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

	PR fortran/38657
	* gfortran.dg/module_commons_3.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/module_commons_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/module.c
    trunk/gcc/testsuite/ChangeLog

Comment 9 Paul Thomas 2009-01-05 19:47:06 UTC
Trunk done, 4.3 to come!

Thanks for the report.

Paul
Comment 10 Paul Thomas 2009-01-10 21:06:40 UTC
Subject: Bug 38657

Author: pault
Date: Sat Jan 10 21:06:27 2009
New Revision: 143249

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

	PR fortran/38657
	* module.c (write_common_0): Use the name of the symtree rather
	than the common block, to determine if the common has been
	written.

2009-01-10  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/38657
	* gfortran.dg/module_commons_3.f90: New test.


Added:
    branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/module_commons_3.f90
Modified:
    branches/gcc-4_3-branch/gcc/fortran/ChangeLog
    branches/gcc-4_3-branch/gcc/fortran/module.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

Comment 11 Paul Thomas 2009-01-10 21:45:44 UTC
Fixed on trunk and 4.3

Paul
Comment 12 Paul Thomas 2009-01-17 08:39:54 UTC
The fix has caused the regression reported in http://gcc.gnu.org/ml/fortran/2009-01/msg00197.html so I am reverting on trunk and 4.3.

Cheers

Paul
Comment 13 Paul Thomas 2009-01-17 09:29:00 UTC
Subject: Bug 38657

Author: pault
Date: Sat Jan 17 09:28:50 2009
New Revision: 143458

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

	PR fortran/38657
	* module.c (write_common_0): Revert patch of 2009-01-10.

2009-01-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/38657
	* gfortran.dg/module_commons_3.f90: Remove


Removed:
    branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/module_commons_3.f90
Modified:
    branches/gcc-4_3-branch/gcc/fortran/ChangeLog
    branches/gcc-4_3-branch/gcc/fortran/module.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

Comment 14 Paul Thomas 2009-01-17 09:44:11 UTC
Subject: Bug 38657

Author: pault
Date: Sat Jan 17 09:43:57 2009
New Revision: 143459

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

	PR fortran/38657
	* module.c (write_common_0): Revert patch of 2009-01-10.

2009-01-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/38657
	* gfortran.dg/module_commons_3.f90: Remove


Removed:
    trunk/gcc/testsuite/gfortran.dg/module_commons_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/module.c
    trunk/gcc/testsuite/ChangeLog

Comment 15 Paul Thomas 2009-01-17 11:58:58 UTC
Subject: Bug 38657

Author: pault
Date: Sat Jan 17 11:58:48 2009
New Revision: 143463

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

	PR fortran/38657
	* module.c (write_common_0): Add argument 'this_module' and
	check that non-use associated common blocks are written first.
	(write_common): Call write_common_0 twice, once with true and
	then with false.

2009-01-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/38657
	* gfortran.dg/module_commons_3.f90: Reapply.

Added:
    trunk/gcc/testsuite/gfortran.dg/module_commons_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/module.c
    trunk/gcc/testsuite/ChangeLog

Comment 16 Richard Biener 2009-01-24 10:21:08 UTC
GCC 4.3.3 is being released, adjusting target milestone.
Comment 17 Paul Thomas 2009-01-26 05:12:15 UTC
Subject: Bug 38657

Author: pault
Date: Mon Jan 26 05:12:03 2009
New Revision: 143669

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

	PR fortran/38657
	* module.c (write_common_0): Add argument 'this_module' and
	check that non-use associated common blocks are written first.
	(write_common): Call write_common_0 twice, once with true and
	then with false.

2009-01-26  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/38657
	* gfortran.dg/module_commons_3.f90: Reapply.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/module_commons_3.f90
Modified:
    branches/gcc-4_3-branch/gcc/fortran/ChangeLog
    branches/gcc-4_3-branch/gcc/fortran/module.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

Comment 18 Paul Thomas 2009-01-26 05:13:13 UTC
Fixed on trunk and 4.3

Paul