[llvm-branch-commits] [clang] f6cf58e - [clang] [MinGW] Tolerate mingw specific linker options during compilation (#67891)
Tobias Hieta via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Oct 2 09:15:36 PDT 2023
Author: Martin Storsjö
Date: 2023-10-02T18:13:03+02:00
New Revision: f6cf58eed9737cb8718465c4fb6917ca854b1bc3
URL: https://github.com/llvm/llvm-project/commit/f6cf58eed9737cb8718465c4fb6917ca854b1bc3
DIFF: https://github.com/llvm/llvm-project/commit/f6cf58eed9737cb8718465c4fb6917ca854b1bc3.diff
LOG: [clang] [MinGW] Tolerate mingw specific linker options during compilation (#67891)
Prior to 591c4b64b3650884c2c68eb47d755ebb62981b99, 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
a79995ca6004082774a87f7a58ab6be5343364b7, 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.
(cherry picked from commit e39de2b8862ae43459324da84279366997265078)
Adapted from the original commit; the test in the original commit
depended on f39c399d9d15efe8309d8aa3d0ecf62205e6c474. Instead of
using -###, when we're not actually using the printed output of
-###, instead use -fdriver-only.
Added:
clang/test/Driver/mingw-linker-options.c
Modified:
clang/lib/Driver/ToolChains/MinGW.cpp
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp b/clang/lib/Driver/ToolChains/MinGW.cpp
index b47041dcca7024e..eaec1d22e6e554c 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -699,8 +699,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(
diff --git a/clang/test/Driver/mingw-linker-options.c b/clang/test/Driver/mingw-linker-options.c
new file mode 100644
index 000000000000000..923e0de5da29182
--- /dev/null
+++ b/clang/test/Driver/mingw-linker-options.c
@@ -0,0 +1,10 @@
+// RUN: %clang --target=x86_64-windows-gnu -c -mwindows %s -fdriver-only 2>&1 | FileCheck %s --check-prefix=WARNING
+// RUN: %clang --target=x86_64-windows-gnu -c -mconsole %s -fdriver-only 2>&1 | FileCheck %s --check-prefix=WARNING
+// RUN: %clang --target=x86_64-windows-gnu -c -mdll %s -fdriver-only 2>&1 | FileCheck %s --check-prefix=WARNING
+// RUN: %clang --target=x86_64-windows-gnu -c -mthreads %s -fdriver-only 2>&1 | FileCheck %s --check-prefix=WARNING
+// RUN: not %clang --target=x86_64-windows-msvc -c -mwindows %s -fdriver-only 2>&1 | FileCheck %s --check-prefix=ERROR
+// RUN: not %clang --target=x86_64-windows-msvc -c -mconsole %s -fdriver-only 2>&1 | FileCheck %s --check-prefix=ERROR
+// RUN: not %clang --target=x86_64-windows-msvc -c -mdll %s -fdriver-only 2>&1 | FileCheck %s --check-prefix=ERROR
+// RUN: not %clang --target=x86_64-windows-msvc -c -mthreads %s -fdriver-only 2>&1 | FileCheck %s --check-prefix=ERROR
+// WARNING: warning: argument unused during compilation: '{{.*}}' [-Wunused-command-line-argument]
+// ERROR: error: unsupported option '{{.*}}' for target '{{.*}}'
More information about the llvm-branch-commits
mailing list