Skip to content

Commit

Permalink
[clang] [MinGW] Tolerate mingw specific linker options during compila…
Browse files Browse the repository at this point in the history
…tion (#67891)

Prior to 591c4b6, the mingw specific
linker options -mthreads, -mconsole, -mwindows and -mdll would be
tolerated also at compile time, but generating a warning about being
unused.

After that commit, they were marked as target specific, which means that
it's an error if they're unused (which would consider them used for the
wrong target). These specific options are only relevant when linking,
but we want to tolerate them at compile time too, like before.

This was fixed for -mthreads in
a79995c, while the other options didn't
seem to be commonly used during compilation.

After the 17.x release, we've got more reports about this actually being
an issue, in #64464. Therefore, apply the same fix for them; marking
them as tolerated for mingw targets during compilation, even if they're
unused. Also add a testcase for -mthreads which was already handled.

Thus, this fixes #64464.
  • Loading branch information
mstorsjo committed Oct 1, 2023
1 parent 95f4b2a commit e39de2b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions clang/lib/Driver/ToolChains/MinGW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,11 @@ void toolchains::MinGW::addClangTargetOptions(
}
}

if (Arg *A = DriverArgs.getLastArgNoClaim(options::OPT_mthreads))
A->ignoreTargetSpecific();
for (auto Opt : {options::OPT_mthreads, options::OPT_mwindows,
options::OPT_mconsole, options::OPT_mdll}) {
if (Arg *A = DriverArgs.getLastArgNoClaim(Opt))
A->ignoreTargetSpecific();
}
}

void toolchains::MinGW::AddClangCXXStdlibIncludeArgs(
Expand Down
10 changes: 10 additions & 0 deletions clang/test/Driver/mingw-linker-options.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %clang --target=x86_64-windows-gnu -c -mwindows %s -### 2>&1 | FileCheck %s --check-prefix=WARNING
// RUN: %clang --target=x86_64-windows-gnu -c -mconsole %s -### 2>&1 | FileCheck %s --check-prefix=WARNING
// RUN: %clang --target=x86_64-windows-gnu -c -mdll %s -### 2>&1 | FileCheck %s --check-prefix=WARNING
// RUN: %clang --target=x86_64-windows-gnu -c -mthreads %s -### 2>&1 | FileCheck %s --check-prefix=WARNING
// RUN: not %clang --target=x86_64-windows-msvc -c -mwindows %s -### 2>&1 | FileCheck %s --check-prefix=ERROR
// RUN: not %clang --target=x86_64-windows-msvc -c -mconsole %s -### 2>&1 | FileCheck %s --check-prefix=ERROR
// RUN: not %clang --target=x86_64-windows-msvc -c -mdll %s -### 2>&1 | FileCheck %s --check-prefix=ERROR
// RUN: not %clang --target=x86_64-windows-msvc -c -mthreads %s -### 2>&1 | FileCheck %s --check-prefix=ERROR
// WARNING: warning: argument unused during compilation: '{{.*}}' [-Wunused-command-line-argument]
// ERROR: error: unsupported option '{{.*}}' for target '{{.*}}'

0 comments on commit e39de2b

Please sign in to comment.