This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH,fortran]: fix bind(c) common block alignment


hi Tobias,

currently, the patch only changes the alignment if the common block is bind(c), which means the compiler should have already verified that the common block fields interop with C.

as to why we weren't seeing it before, i do not know. the bind_c_coms.f90/bind_c_coms_driver.c illustrates on x86 linux that there is a difference in the alignment. the generated assembly shows it, but the linker didn't complain.

if it is acceptable for all common blocks to choose a C compatible alignment, then the patch is trivial to change to do this. is that what people prefer?

Chris

On Mon, 6 Aug 2007, Tobias Schlüter wrote:

Christopher D. Rickett wrote:
as mentioned previously on the list by Jack Howarth, there is a mismatch in alignment with bind(c) common blocks. the Fortran compiler simply sets the alignment of all common blocks to BIGGEST_ALIGN, while the C compiler tries to align based on the size of the fields in the interoperable C struct. the attached patch should fix the alignment difference by changing the alignment setting of bind(c) common blocks.

How often does this change something? It is a fairly widespread assumption that COMMON blocks can be mapped to C structs (e.g. I recall there being an example of doing this in the ROOT manual, and a quick websearch reveals lots of pages that describe this as a fact). I.e. that
COMMON /X/A,B,I(7),C
maps to
struct { float a, b; int i[7]; float c; }
etc.
Since this seems to be really common, I'm surprised that we weren't hit by this before.


I think we should choose C compatible alignments everywhere possible.

A testcase that triggers on i86 would also be a good idea.

Cheers,
- Tobi

bootstrapped and regtested on x86 linux with no new failures.

ChangeLog entry:

2007-08-06 Christopher D. Rickett <crickett@lanl.gov>

    * trans-common.c (build_common_decl): Fix the alignment for
    BIND(C) common blocks.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]