Bug 95106 - Bogus warning from module with long name and an equivalence
Summary: Bogus warning from module with long name and an equivalence
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 11.0
: P4 normal
Target Milestone: ---
Assignee: anlauf
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2020-05-13 16:19 UTC by G. Steinmetz
Modified: 2020-06-05 20:35 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-05-21 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description G. Steinmetz 2020-05-13 16:19:15 UTC
Name length 59 ok, suspicious warning for 60..63 :


$ cat z1_59.f90
module m2345678901234567890123456789012345678901234567890123456789
   real :: a(4), u(3,2)
   real :: b(4), v(4,2)
   equivalence (a(1),u(1,1)), (b(1),v(1,1))
end


$ cat z1_60.f90
module m23456789012345678901234567890123456789012345678901234567890
   real :: a(4), u(3,2)
   real :: b(4), v(4,2)
   equivalence (a(1),u(1,1)), (b(1),v(1,1))
end


$ cat z1_63.f90
module m23456789012345678901234567890123456789012345678901234567890123
   real :: a(4), u(3,2)
   real :: b(4), v(4,2)
   equivalence (a(1),u(1,1)), (b(1),v(1,1))
end


$ gfortran-11-20200510 -c z1_59.f90
$
$ gfortran-11-20200510 -c z1_60.f90
z1_60.f90:1:67:

    1 | module m23456789012345678901234567890123456789012345678901234567890
      |                                                                   1
Warning: Named COMMON block 'm23456789012345678901234567890123456789012345678901234567890.eq.1' at (1) shall be of the same size as elsewhere (24 vs 32 bytes)
Comment 1 anlauf 2020-05-21 20:15:24 UTC
The warning is not only bogus, but indicates that something goes wrong.

Doing an "nm" on the resulting object files, it seems one equivalence is
missing for names of length 60+.

For z1_59.o:

0000000000000020 C m2345678901234567890123456789012345678901234567890123456789.eq.0_
0000000000000018 C m2345678901234567890123456789012345678901234567890123456789.eq.1_

For z1_60.o:

0000000000000020 C m23456789012345678901234567890123456789012345678901234567890.eq._

It seems it cannot disambiguate the two equivalences any more,
and treat them as a single common.
Comment 2 anlauf 2020-05-21 20:49:07 UTC
Something like

diff --git a/gcc/fortran/trans-common.c b/gcc/fortran/trans-common.c
index bf163bc4f52..06313873002 100644
--- a/gcc/fortran/trans-common.c
+++ b/gcc/fortran/trans-common.c
@@ -242,8 +242,8 @@ static tree
 gfc_sym_mangled_common_id (gfc_common_head *com)
 {
   int has_underscore;
-  char mangled_name[GFC_MAX_MANGLED_SYMBOL_LEN + 1];
-  char name[GFC_MAX_SYMBOL_LEN + 1];
+  char mangled_name[GFC_MAX_MANGLED_SYMBOL_LEN + 10];
+  char name[GFC_MAX_SYMBOL_LEN + 10];
 
   /* Get the name out of the common block pointer.  */
   strcpy (name, com->name);

prevents the truncation of the mangled name, including the .eq.0123_ part.
Comment 3 anlauf 2020-05-22 18:43:54 UTC
Patch submitted for review:

https://gcc.gnu.org/pipermail/fortran/2020-May/054373.html
Comment 4 GCC Commits 2020-05-24 19:35:32 UTC
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:d176184d98a00ab379ae5959aed1908a79995e6b

commit r11-594-gd176184d98a00ab379ae5959aed1908a79995e6b
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Sun May 24 21:35:04 2020 +0200

    PR fortran/95106 - truncation of long symbol names with EQUIVALENCE
    
            For long module names, the generated name-mangled symbol was
            truncated, leading to bogus warnings about COMMON block
            mismatches.  Provide sufficiently large temporaries.
    
    gcc/fortran/
    
    2020-05-24  Harald Anlauf  <anlauf@gmx.de>
    
            PR fortran/95106
            * trans-common.c (gfc_sym_mangled_common_id): Enlarge temporaries
            for name-mangling.
    
    gcc/testsuite/
    
    2020-05-24  Harald Anlauf  <anlauf@gmx.de>
    
            PR fortran/95106
            * gfortran.dg/equiv_11.f90: New test.
Comment 5 anlauf 2020-05-24 19:39:08 UTC
Should be fixed, closing.

The test case assumes name mangling for equivalences as on Linux/x86.
If some platform has different conventions, I can add an appropriate
restriction.

Thanks for the report!
Comment 6 GCC Commits 2020-06-05 19:55:32 UTC
The releases/gcc-10 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:1e20cd1b583347cb2ea8591a45d99df143f7c41a

commit r10-8255-g1e20cd1b583347cb2ea8591a45d99df143f7c41a
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Sun May 24 21:35:04 2020 +0200

    PR fortran/95106 - truncation of long symbol names with EQUIVALENCE
    
            For long module names, the generated name-mangled symbol was
            truncated, leading to bogus warnings about COMMON block
            mismatches.  Provide sufficiently large temporaries.
    
    gcc/fortran/
    
    2020-05-24  Harald Anlauf  <anlauf@gmx.de>
    
            PR fortran/95106
            * trans-common.c (gfc_sym_mangled_common_id): Enlarge temporaries
            for name-mangling.
    
    gcc/testsuite/
    
    2020-05-24  Harald Anlauf  <anlauf@gmx.de>
    
            PR fortran/95106
            * gfortran.dg/equiv_11.f90: New test.
Comment 7 GCC Commits 2020-06-05 20:35:31 UTC
The releases/gcc-9 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:371739d01d00ae4c55902e0937b73ddee7d66391

commit r9-8655-g371739d01d00ae4c55902e0937b73ddee7d66391
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Sun May 24 21:35:04 2020 +0200

    PR fortran/95106 - truncation of long symbol names with EQUIVALENCE
    
            For long module names, the generated name-mangled symbol was
            truncated, leading to bogus warnings about COMMON block
            mismatches.  Provide sufficiently large temporaries.
    
    gcc/fortran/
    
    2020-05-24  Harald Anlauf  <anlauf@gmx.de>
    
            PR fortran/95106
            * trans-common.c (gfc_sym_mangled_common_id): Enlarge temporaries
            for name-mangling.
    
    gcc/testsuite/
    
    2020-05-24  Harald Anlauf  <anlauf@gmx.de>
    
            PR fortran/95106
            * gfortran.dg/equiv_11.f90: New test.
    
    (cherry picked from commit d176184d98a00ab379ae5959aed1908a79995e6b)