<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/66969>66969</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Flang not respecting `-module` flag
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          h-vetinari
      </td>
    </tr>
</table>

<pre>
    While [trying](https://github.com/conda-forge/scipy-feedstock/pull/252) to get flang working on a project that uses the meson build system, we ran into:

```
[133/1628] Compiling Fortran object scipy/special/libamos.a.p/amos_dgamln.f.obj
FAILED: scipy/special/libamos.a.p/amos_dgamln.f.obj 
"flang-new" "-Iscipy\special\libamos.a.p" "-Iscipy\special" "-I..\scipy\special" "-fcolor-diagnostics" "-DNDEBUG" "-D_FILE_OFFSET_BITS=64" "-O3" "-module" "scipy\special\libamos.a.p" -MD -MQ scipy/special/libamos.a.p/amos_dgamln.f.obj -MF "scipy\special\libamos.a.p\amos_dgamln.f.obj.d" -o scipy/special/libamos.a.p/amos_dgamln.f.obj "-c" ../scipy/special/amos/dgamln.f
flang-new: error: unknown argument: '-module'

flang-new: warning: scipy\special\libamos.a.p: 'linker' input unused
```
This is because `-module` is apparently so common in Fortran compilers, that it's the [baseline](https://github.com/mesonbuild/meson/blob/1.2.1/mesonbuild/compilers/fortran.py#L94-L95) assumption for how meson constructs its commandline invocations for most Fortran compilers (it's worth noting that this method gets overridden for several compilers, though notably, meson for classic flang defaults to `-module`).

It seems this assumption matches parts of flang's documentation (which do indicate `-module` support)...
https://github.com/llvm/llvm-project/blob/2147e9e09f83042defdace45eb73580e1f0f5c28/flang/docs/ModFiles.md?plain=1#L106-L121

... but not [others](https://flang.llvm.org/docs/FlangCommandLineReference.html#cmdoption-flang-module-dir-dir), which say:
> -module-dir\<dir>, -J\<arg>

> This option specifies where to put .mod files for compiled modules. It is also added to the list of directories to be searched by an USE statement. The default is the current directory.

I'm not sure if this was an oversight in the recent option-refactor. It's certainly conceivable to teach meson that (llvm-)flang needs `-module-dir` instead of `-module`. However, it's at least surprising (given the documentation divergence), so I thought I'd raise this.

CC @banach-space 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVl2PozgW_TXOy1UQmJCEhzx0JcVurap3tNs92seWsS_gKWMj21SUf7-6Jqmq9PRMa0YqVYzhfvjccw6IEHRvEQ-semDVaSXmODh_GNavGLUVXq9apy6H_w3aILDqIfqLtj2rTozvhxinwMpPjDeMN72Ow9xm0o2MN9JZJdad8z0y3gSpp8u6Q1QhOvnCeDPNxjDe8IozXkN00GOEzgjbw9n5F217cBYETN79hjJCHESEOWCAOCCMGJyFdtZGQbiEiCPjRzgjeGFB2-ioqfzE8tv_bX79Wy6rh6IsGW-KLd-z6gRHN07aUNHG-UhJXJvKpsbpABNKLahjo1sxupCJbGK8oeU31YvR2KzLXPvbUqD59PT8eGLlp7-eAK4tcp7QWFs8M86Bcb5-WpJVx1uy6niX7A-euu1nGW3--GYnnXF-rbTorQtRy3C7c_r36fHh13-8XX5rnp4fv_3SNF8ev357ePr6hZWn7eZ2-5fythqdmg1er37a-PrzCdaf__M34Fp_bn5eoTr-LjBTqa77OxPifC0pOstu3L6LpwjGm1vMMtD3aZafAL13nhazfbHubEH4fh7RRtpjfPeG3u4ji-9SnIW3JMQ3jv3R2ZeMRtsX9IzvQNtpjjDbOaD6oTq-DjqADtCiFHNAYNv81s82pxtimoRHG80FggPpxtGR6t60I5Oa0AcSZRKujozvFumy6qEVAY22-FMTSTJPKr9dMN60xrUk3YxnxffPfKjcdEs3GQ2nfK436-e6Iq8RIczjFLWz0DkPgztf7UQ6G6KfZQygY0jnElZRo6Dtq5OCYkIKGl2Ivz8uML6_nvTsfBzAukiekiCIhOqIcXCKvC6Ae0XvtVK49BHwFb0w34Pn5j7lEa250M7SKgVIQ9Ytr6apsBOziYGs9G5gjNfZRxI9RQiIY1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