Strange failure with ficticious Fortran module dependency

I discovered an odd failure while attempting to port a large (mostly-)Fortran project to cmake+ninja under Msys2.

The failure is clearly in the Fortran source code parser attempting to search for “module” statements, which misfires on the line in my codebase:

      call io_abort("Error in "//subroutine_name//": attempting to initialise ion_ion &
                    &module when module has already been initialised.")

The parser erroneously imagines it spots the start of a new module, failing to notice that the text “module when” is part of a quoted string, continued from the previous line. This generates a .ddi file containing

   "provides" :
     [
         {
             "compiled-module-path" : "mod/ion_ion.mod",
             "logical-name" : "ion_ion.mod"
         }
         {
             "compiled-module-path" : "mod/when.mod",
             "logical-name" : "when.mod"
         }
     ],

and ultimately leads to an aborted build with
ninja: build stopped: multiple rules generate mod/when.mod.

This failure occurs in msys2/ucrt64 on Windows 10 with cmake 2.24.2 and ninja 1.11.1. It is specific to the cmake-24.2 series; fortunately I have been able to test 23.x and 25.x, which turn out to be free of this issue. It is also specific to Windows and MSYS2, and can not be reproduced on linux with the same versions of cmake.

I wondered if the failure to detect a continued quoted string might be due to some issue with regexp matching and windows like endings? (However running unix2dos on the test file makes no difference). Any thoughts/suggestions welcome.

This is easily reproduced in this testcase

Keith Refson

I don’t think this has to do with Windows line endings. I suspect our Fortran grammar doesn’t understand &-based line continuations?

Agreed. When I tested with different line endings it made no difference.

But it’s hard to understand why the Fortran lexer fails ONLY on MSYS2 and not on other platforms. (And only with the 3.24.x releases too)

K.

Oh, weird. MSYS2-specific certainly sounds odd. There were some Fortran parser changes recently:

though these are in 3.25, not 3.24.

So these may be the changes that fixed the issue… :slightly_smiling_face:?

As it took a peculiar and rare intersection of

  • the text “module when …” immediately on the left of a continued string
  • this in more than one module
  • Ninja to detect and abort on multiple modules with the same name
  • Some undetermined platform-dependent additional factor

for this to be noticed it might still be useful to double check that the lexer handles continuation lines within quoted correctly.

Probably. The only change I see for 3.24 in the Fortran parsers are some clang-tidy fixes, a warning suppression, and regenerating the parsers with Bison 3.8.2. If I had to bet, the last one feels the most likely to have caused a problem.

Agreed.