Skip to content

Commit f6cf58e

Browse files
mstorsjotru
authored andcommitted
[clang] [MinGW] Tolerate mingw specific linker options during compilation (llvm#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 llvm#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 llvm#64464. (cherry picked from commit e39de2b) Adapted from the original commit; the test in the original commit depended on f39c399. Instead of using -###, when we're not actually using the printed output of -###, instead use -fdriver-only.
1 parent b338a28 commit f6cf58e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

clang/lib/Driver/ToolChains/MinGW.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,8 +699,11 @@ void toolchains::MinGW::addClangTargetOptions(
699699
}
700700
}
701701

702-
if (Arg *A = DriverArgs.getLastArgNoClaim(options::OPT_mthreads))
703-
A->ignoreTargetSpecific();
702+
for (auto Opt : {options::OPT_mthreads, options::OPT_mwindows,
703+
options::OPT_mconsole, options::OPT_mdll}) {
704+
if (Arg *A = DriverArgs.getLastArgNoClaim(Opt))
705+
A->ignoreTargetSpecific();
706+
}
704707
}
705708

706709
void toolchains::MinGW::AddClangCXXStdlibIncludeArgs(
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang --target=x86_64-windows-gnu -c -mwindows %s -fdriver-only 2>&1 | FileCheck %s --check-prefix=WARNING
2+
// RUN: %clang --target=x86_64-windows-gnu -c -mconsole %s -fdriver-only 2>&1 | FileCheck %s --check-prefix=WARNING
3+
// RUN: %clang --target=x86_64-windows-gnu -c -mdll %s -fdriver-only 2>&1 | FileCheck %s --check-prefix=WARNING
4+
// RUN: %clang --target=x86_64-windows-gnu -c -mthreads %s -fdriver-only 2>&1 | FileCheck %s --check-prefix=WARNING
5+
// RUN: not %clang --target=x86_64-windows-msvc -c -mwindows %s -fdriver-only 2>&1 | FileCheck %s --check-prefix=ERROR
6+
// RUN: not %clang --target=x86_64-windows-msvc -c -mconsole %s -fdriver-only 2>&1 | FileCheck %s --check-prefix=ERROR
7+
// RUN: not %clang --target=x86_64-windows-msvc -c -mdll %s -fdriver-only 2>&1 | FileCheck %s --check-prefix=ERROR
8+
// RUN: not %clang --target=x86_64-windows-msvc -c -mthreads %s -fdriver-only 2>&1 | FileCheck %s --check-prefix=ERROR
9+
// WARNING: warning: argument unused during compilation: '{{.*}}' [-Wunused-command-line-argument]
10+
// ERROR: error: unsupported option '{{.*}}' for target '{{.*}}'

0 commit comments

Comments
 (0)