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

    <tr>
        <th>Summary</th>
        <td>
            [flang] LIT failure in Driver/linker-flags.f90 test case when the default linker is lld
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          amy-kwan
      </td>
    </tr>
</table>

<pre>
    I am building on the PowerPC platform and I am observing the following LIT failure where an expected CHECK for the MSVC target is not found. This occurs when building the flang project and when setting the default Clang linker to lld:
```
$  /home/amyk/testbuild3/bin/flang-new -### -flang-experimental-exec -target aarch64-windows-msvc /data/amyk/compiler/community/llvm-project/flang/test/Driver/Inputs/hello.f90 2>&1 | /home/amyk/testbuild3/bin/FileCheck /data/amyk/compiler/community/llvm-project/flang/test/Driver/linker-flags.f90 --check-prefixes=CHECK,MSVC --implicit-check-not libcmt --implicit-check-not oldnames
/data/amyk/compiler/community/llvm-project/flang/test/Driver/linker-flags.f90:40:15: error: MSVC-LABEL: expected string not found in input
! MSVC-LABEL: link.exe
              ^
<stdin>:5:106: note: scanning from here
 "/home/amyk/testbuild3/bin/flang-new" "-fc1" "-triple" "aarch64-unknown-windows-msvc19.20.0" "-emit-obj" "-o" "/tmp/hello-ddf5b3.o" "-x" "f95-cpp-input" "/data/amyk/compiler/community/llvm-project/flang/test/Driver/Inputs/hello.f90"
                                                                                                         ^
<stdin>:6:33: note: possible intended match here
 "/home/amyk/testbuild3/bin/lld-link" "-out:a.exe" "-libpath:lib/arm64" "-libpath:atlmfc/lib/arm64" "-libpath:/home/amyk/testbuild3/lib" "Fortran_main.lib" "FortranRuntime.lib" "FortranDecimal.lib" "/subsystem:console" "-nologo" "/tmp/hello-ddf5b3.o"
                                ^

Input file: <stdin>
Check file: /data/amyk/compiler/community/llvm-project/flang/test/Driver/linker-flags.f90

-dump-input=help explains the following input dump.

Input was:
<<<<<<
            1: flang-new version 15.0.0 (git@github.com:llvm/llvm-project.git fd8fd9e51cbeb76d290ceda941fd8b7d5a4151bc)
            2: Target: aarch64-unknown-windows-msvc
            3: Thread model: posix
            4: InstalledDir: /home/amyk/testbuild3/bin
            5:  "/home/amyk/testbuild3/bin/flang-new" "-fc1" "-triple" "aarch64-unknown-windows-msvc19.20.0" "-emit-obj" "-o" "/tmp/hello-ddf5b3.o" "-x" "f95-cpp-input" "/data/amyk/compiler/community/llvm-project/flang/test/Driver/Inputs/hello.f90"
label:40'0                                                                                                              X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
            6:  "/home/amyk/testbuild3/bin/lld-link" "-out:a.exe" "-libpath:lib/arm64" "-libpath:atlmfc/lib/arm64" "-libpath:/home/amyk/testbuild3/lib" "Fortran_main.lib" "FortranRuntime.lib" "FortranDecimal.lib" "/subsystem:console" "-nologo" "/tmp/hello-ddf5b3.o"
label:40'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
label:40'1                                     ?                                                                                                                                                                                                                           possible intended match
>>>>>>
```

This test case was updated by the following commit:
```
commit 26041e17006cf30e9c2d06706fe6bd3fa818e356
Author: Diana Picus <diana.picus@linaro.org>
Date:   Fri Dec 10 22:02:32 2021 +0000

    Update link job for flang on windows

    When linking a Fortran program, we need to add the runtime libraries to
    the command line. This is exactly what we do for Linux/Darwin, but the
    MSVC interface is slightly different (e.g. -libpath instead of -L).

    We also remove oldnames and libcmt, since they're not needed at the
    moment and they bring in more dependencies.

    We also pass `/subsystem:console` to the linker so it can figure out the
    right entry point. This is only needed for MSVC's `link.exe`. For LLD it
    is redundant but doesn't hurt.

    Differential Revision: https://reviews.llvm.org/D126291

    Co-authored-by: Markus Mützel <markus.muetzel@gmx.de>
```

For reference, my build invocations are the following (note the `-DCLANG_DEFAULT_LINKER=lld`):
```
$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=OFF  '-DLLVM_ENABLE_PROJECTS=llvm;clang;clang-tools-extra;lld;mlir;flang' -DLLVM_LIT_ARGS="-sv -j 48" '-DLLVM_ENABLE_RUNTIMES=;compiler-rt;libcxx;libcxxabi' -DLLVM_BINUTILS_INCDIR=/usr/include/ -DCLANG_DEFAULT_LINKER=lld /data/amyk/compiler/community/llvm-project/llvm
$ ninja
```

The test case expects to find `"link.exe"` for the MSVC target, but when `-DCLANG_DEFAULT_LINKER=lld` is set, the actual output is `lld-link` instead, as seen on the link invocation on the second line:
``` bash
$ /home/amyk/testbuild3/bin/flang-new -### -flang-experimental-exec -target aarch64-windows-msvc /data/amyk/compiler/community/llvm-project/flang/test/Driver/Inputs/hello.f90
flang-new version 15.0.0 (git@github.com:llvm/llvm-project.git fd8fd9e51cbeb76d290ceda941fd8b7d5a4151bc)
Target: aarch64-unknown-windows-msvc
Thread model: posix
InstalledDir: /home/amyk/testbuild3/bin
 "/home/amyk/testbuild3/bin/flang-new" "-fc1" "-triple" "aarch64-unknown-windows-msvc19.20.0" "-emit-obj" "-fcolor-diagnostics" "-o" "/tmp/hello-003fe1.o" "-x" "f95-cpp-input" "/data/amyk/compiler/community/llvm-project/flang/test/Driver/Inputs/hello.f90"
 "/home/amyk/testbuild3/bin/lld-link" "-out:a.exe" "-libpath:lib/arm64" "-libpath:atlmfc/lib/arm64" "-libpath:/home/amyk/testbuild3/lib" "Fortran_main.lib" "FortranRuntime.lib" "FortranDecimal.lib" "/subsystem:console" "-nologo" "/tmp/hello-003fe1.o"
```

The expected `"link.exe"` is found in a build when lld is not set as the default linker:
``` bash
$ /home/amyk/testbuild2/bin/flang-new -### -flang-experimental-exec -target aarch64-windows-msvc /data/amyk/compiler/community/llvm-project/flang/test/Driver/Inputs/hello.f90
flang-new version 15.0.0 (git@github.com:llvm/llvm-project.git fd8fd9e51cbeb76d290ceda941fd8b7d5a4151bc)
Target: aarch64-unknown-windows-msvc
Thread model: posix
InstalledDir: /home/amyk/testbuild2/bin
flang-new: warning: unable to find a Visual Studio installation; try running Clang from a developer command prompt
 "/home/amyk/testbuild2/bin/flang-new" "-fc1" "-triple" "aarch64-unknown-windows-msvc19.20.0" "-emit-obj" "-fcolor-diagnostics" "-o" "/tmp/hello-12f969.o" "-x" "f95-cpp-input" "/data/amyk/compiler/community/llvm-project/flang/test/Driver/Inputs/hello.f90"
 "link.exe" "-out:a.exe" "-libpath:lib/arm64" "-libpath:atlmfc/lib/arm64" "-libpath:/home/amyk/testbuild2/lib" "Fortran_main.lib" "FortranRuntime.lib" "FortranDecimal.lib" "/subsystem:console" "-nologo" "/tmp/hello-12f969.o"
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztWltz4joS_jXworLLFzDhgQcCZJYdJpNKyOzuU0q2ZVBiS5QkB3J-_XbLNhDIdebMTrYqlMs33brV3V9fTCzTh8GU0ILEJc9TLhZECmKWjFzINVMXI7LKqcmkKggVKbE9ZayZuseu2C-TeS7X-DSbzklGeV4qRtZLBmcqCNusWGJYSkb_mIy-Qm9lR327-jEihqoFM4RrIqSBplKkLpkv4VkmSak0ziJ2hNnVcgp3KyVvYVZLku2jmTFNl5RltMwNGdmuORd3DNaUJM_TVjhseeOWN2xFXn1Uj0GHkFZwtpQFgwstHu7gYpg2dvEQHmIu4GyXdwRbE6cVhNVBnOotcqp4wYShOTywhDg1g5S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