andreww / fox

A Fortran XML library
https://andreww.github.io/fox/
Other
58 stars 50 forks source link

Compilation issues with recent gfortran versions (6.4.1 and 7.3.1) #57

Open pietrodelugas opened 6 years ago

pietrodelugas commented 6 years ago

There is a bug introduced in recent versions of gfortran (6.4.1, 7.3.1 ). These versions raise an internal compiler error when compiling FoX.

I made a bug report to gcc ( https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85526 ).

As far as I understand the bug is related to the usage of the len interface to compute the dimensions of the results of character type of many pure functions used for example in fox_m_fsys_format.F90 or in m_dom_dom.F90.

A workaround that seems to work is to move the routines involved in the len interface at the bottom of their modules, but as explained by a note in the code this clashes with an explicit fortran specification and the modified source is not accepted as valid by other compilers.

A more stable workaround could be to move the len interface to a new module and import the interface.

andreww commented 6 years ago

Thanks for this. So I should also add more gcc compilers to the mix of the CI. What fun!

I think the latest suggestion in the gcc bug report (just move the checkFmt function to the top of the file) will give us something that compiles with the latest gcc compilers (working around the bug) and is valid Fortran 2008. I say think because I am struggling a bit with:

If a specification expression in the specification-part of a module or submodule includes a reference to a generic entity, that generic entity shall have no specific procedures defined in the module or submodule subsequent to the specification expression.
(Paragraph 9 of section 7.2.11 of the Fortran2008 specification)

We don't reference the generic entity in checkFmt so this compiler bug workaround should be OK. But validating this for the Cray compiler (which seems to be the only compiler that enforces this constraint) would be useful. I wonder if NAG does this yet...

pietrodelugas commented 6 years ago

Yes it works with gfortran and pgi. Much simpler that I was afraid. There is also another function get_TextContent_len to move upwards, It is in dom/m_dom_dom.F90, should be done in the m4 file but I don't know how to do. I will do more tests with intel and let you know

butala commented 5 years ago

Just writing to say that I experienced the same problems as above with gfortran (7.3.0), moved the functions checkFmt and get_TextContent_len as suggested, and I was able to build successfully.

andreww commented 3 years ago

Sorry for the delay!

At least a partial fix to this is at https://github.com/libAtoms/fox/commit/1eef7392bb08e9e53f2ec420faef32cd744854b9 and/or https://github.com/ye-luo/fox/commit/e4d04790c85977185696cae1a653a3353d550730

Looks like the gfortran bug ended up getting fixed and the fix got back ported (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85138) but I don't see a problem with these fixes. I'll pull together a patch