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