public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/41227]  New: COMMON block, BIND(C) and LTO interoperability issues
@ 2009-09-02 14:26 burnus at gcc dot gnu dot org
  2009-09-14 21:05 ` [Bug fortran/41227] " burnus at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 22+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-09-02 14:26 UTC (permalink / raw)
  To: gcc-bugs

There are interoperability issues with
   integer :: single_variable
   COMMON /name/ single_variable
and C. Currently, gfortran generates the equivalent to
   struct { int single_variable }
however - at least with BIND(C) - it should be compatible to
   int single_variable

That's what bind_c_coms.f90/bind_c_coms_driver.c test and which is failing with
-flto on the LTO branch.

See Fortran 2003, "15.3 Interoperation with C global variables":

"A C variable with external linkage interoperates with a common block that has 
 been specified in a BIND statement
(1) if the C variable is of a struct type and the variables that are members of
    the common block are interoperable with corresponding components of the
    struct type, or
(2) if the common block contains a single variable, and the variable is
    interoperable with the C variable."

 * * *

Next question: What should happen without BIND(C)?
Answer: In F2003, "5.5.2.4 Differences between named common and blank common"
one finds:

"A blank common block has the same properties as a named common block, except 
 for the following:  [...]
(2) Named common blocks of the same name shall be of the same size in all 
    scoping units of a program in which they appear, but blank common blocks
    may be of different sizes."

By construction, blank common names are not accessible from C. Thus from the
standard, one could do the "struct"-less version for named commons and the
"struct" version for blank commons.

I do not know whether there are compatibility issues with old programs;
however, the general advice was to use "struct".

 * * *

I think one should drop some kind of note in the Release Notes and add a few
words about COMMON to
http://gcc.gnu.org/onlinedocs/gfortran/Mixed_002dLanguage-Programming.html

Another huge issue is padding: In C one has - by default - padding, in Fortran
(according to the language standard) not. gfortran uses padding (cf.
-fno-align-commons), however. One probably should exclude the BIND(C) COMMONS
from the -fno-align-commons option and should check that C does exactly the
same padding.

See also PR 41209 for a means to set, e.g., the padding.


-- 
           Summary: COMMON block, BIND(C) and LTO interoperability issues
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41227


^ permalink raw reply	[flat|nested] 22+ messages in thread
[parent not found: <bug-41227-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2015-05-27 23:55 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-02 14:26 [Bug fortran/41227] New: COMMON block, BIND(C) and LTO interoperability issues burnus at gcc dot gnu dot org
2009-09-14 21:05 ` [Bug fortran/41227] " burnus at gcc dot gnu dot org
2009-09-28 19:59 ` tobi at gcc dot gnu dot org
2010-01-29 17:46 ` burnus at gcc dot gnu dot org
2010-02-02 10:29 ` burnus at gcc dot gnu dot org
2010-02-11 16:29 ` burnus at gcc dot gnu dot org
2010-02-23  9:08 ` burnus at gcc dot gnu dot org
2010-02-23  9:33 ` rguenther at suse dot de
2010-06-03 13:49 ` rguenth at gcc dot gnu dot org
     [not found] <bug-41227-4@http.gcc.gnu.org/bugzilla/>
2012-01-05 13:38 ` rguenth at gcc dot gnu.org
2014-06-08 16:53 ` fxcoudert at gcc dot gnu.org
2014-06-10 13:06 ` rguenth at gcc dot gnu.org
2014-07-14 10:21 ` fxcoudert at gcc dot gnu.org
2014-07-14 10:36 ` rguenther at suse dot de
2014-07-14 10:45 ` fxcoudert at gcc dot gnu.org
2014-07-14 11:09 ` rguenth at gcc dot gnu.org
2014-07-14 11:20 ` fxcoudert at gcc dot gnu.org
2014-07-14 11:36 ` burnus at gcc dot gnu.org
2014-07-14 11:46 ` rguenther at suse dot de
2014-07-14 12:05 ` tobi at gcc dot gnu.org
2014-07-14 13:33 ` burnus at gcc dot gnu.org
2015-05-27 23:55 ` hubicka at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).