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

    <tr>
        <th>Summary</th>
        <td>
            "Remove misused NoXarchOption from some Windows options" broke -mthreads for MinGW
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:driver,
            regression,
            platform:windows
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          mstorsjo
      </td>
    </tr>
</table>

<pre>
    CC @MaskRay @alvinhochun

The recent commit 591c4b64b3650884c2c68eb47d755ebb62981b99, "[Driver] Remove misused NoXarchOption from some Windows options", broke building Qt 5.x with Clang for MinGW targets.

Qt 5.x compiles object files for MinGW/Clang targets with `-mthreads` - see https://github.com/qt/qtbase/blob/v5.15.2/mkspecs/common/g%2B%2B-win32.conf#L34. (It's also used separately when linking, see line 43 in the same file.)

With GCC, the `-mthreads` flag is accepted both when compiling and when linking (I'm unsure if it affects, or maybe at some point in time, affected, code generation, or if it just has been accepted without any specific need).

With Clang, previously, the `-mthreads` flag was tolerated, but passing it when compiling an object file, it produced the following warning:
```
clang: warning: argument unused during compilation: '-mthreads' [-Wunused-command-line-argument]
```
Passing the flag when linking has an actual effect (linking against `-lmingwthrd` - although that library is mostly a dummy stub without any effect these days).

In the case of Qt, the flag is only used at some point during configure - most of the compilation is done without the `-fexception -mthreads` options, so the warnings haven't really been noticed before.

After 591c4b64b3650884c2c68eb47d755ebb62981b99, compiling an object file with this flag produces the following error:
```
clang: error: unsupported option '-mthreads' for target 'x86_64-w64-mingw32'
```

As this flag has been tolerated before (while warning about it) and GCC accepts it without warning, I believe we should accept it too.

We can make Clang accept it (without warning even) with something like this:
```
diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp b/clang/lib/Driver/ToolChains/MinGW.cpp
index 947abb9b02b5..68be68a49080 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -686,6 +686,8 @@ void toolchains::MinGW::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
 void toolchains::MinGW::addClangTargetOptions(
     const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
 Action::OffloadKind DeviceOffloadKind) const {
+ DriverArgs.getLastArg(options::OPT_mthreads);
+
   if (Arg *A = DriverArgs.getLastArg(options::OPT_mguard_EQ)) {
     StringRef GuardArgs = A->getValue();
     if (GuardArgs == "none") {
```
But this isn't very nice, and I somewhat think the previous warning about it being unused when compiling probably is good to have.

I'm not entirely familiar with the `NoXarchOption` flag here, but as far as I can see, the main functional change that breaks things here, is not that `def mthreads` no longer has got `NoXarchOption`, but the issue is that it now has the `TargetSpecific` flag, which apparently makes Clang error out instead of warn if the option hasn't been consumed.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycV9ty4zgO_RrmBWWXQsmy_eAHxxl3pXZme_pS2_vWRYqQxA5FeknKbv_9Fkg5sfsyUz2plG8CwUPg4AAUIejOIm7Y4oEtHu_EGHvnN0OIzocv7k46dd7sdsCq4g8Rnt-LM30U5qht75p-tKx4ZMU2v37sETw2aCM0bhh0hMX6vqlkXcmyXhSrVdXwpl6hrJZquViglDVfr-7les34DhjnbPHw6PURPVs8wnsc3BFh0GEMqODf7r_CN_3bQ9TOQuvdAMENCJ-0Ve4UwKUHgbzwHUjvnhHkqI3StoN3ERbzr3DSsYedEbaD1nn4Q9s3nyAK32EM8-uTTPaNGw7aYAAnv2AToU1fXpYyvs_OJhfZP6uL2RB7j0IFVhcwg4AIfYyHwMot43vG952O_SjnjRsY3_8vphcpAjK-l8ZJxvfHxfx-MeeM74fncMAmML6noDpLyxlf8If0MjtpW_J542zLePl7Wc2B8dVTZHwZQJjgIEUv4EF4EdGc4dSjBaPts7YdhYrQGW0RqhK0hdgjBDFgOuyc8fV1XD7RAd_sdrSODL89a2tEBzqAaBo8RFQgXezzjjmW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