$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
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.
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).
(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).
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.
(In reply to comment #4) > With USE TEST3, sym->backend_decl is not set. Interestingly, the backend_decl for test3's testchar is set.
(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
I'm just about to post a patch. Paul
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
Trunk done, 4.3 to come! Thanks for the report. Paul
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
Fixed on trunk and 4.3 Paul
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
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
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
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
GCC 4.3.3 is being released, adjusting target milestone.
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