Skip to content

Commit e39de2b

Browse files
authored
[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.
1 parent 95f4b2a commit e39de2b

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
@@ -709,8 +709,11 @@ void toolchains::MinGW::addClangTargetOptions(
709709
}
710710
}
711711

712-
if (Arg *A = DriverArgs.getLastArgNoClaim(options::OPT_mthreads))
713-
A->ignoreTargetSpecific();
712+
for (auto Opt : {options::OPT_mthreads, options::OPT_mwindows,
713+
options::OPT_mconsole, options::OPT_mdll}) {
714+
if (Arg *A = DriverArgs.getLastArgNoClaim(Opt))
715+
A->ignoreTargetSpecific();
716+
}
714717
}
715718

716719
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 -### 2>&1 | FileCheck %s --check-prefix=WARNING
2+
// RUN: %clang --target=x86_64-windows-gnu -c -mconsole %s -### 2>&1 | FileCheck %s --check-prefix=WARNING
3+
// RUN: %clang --target=x86_64-windows-gnu -c -mdll %s -### 2>&1 | FileCheck %s --check-prefix=WARNING
4+
// RUN: %clang --target=x86_64-windows-gnu -c -mthreads %s -### 2>&1 | FileCheck %s --check-prefix=WARNING
5+
// RUN: not %clang --target=x86_64-windows-msvc -c -mwindows %s -### 2>&1 | FileCheck %s --check-prefix=ERROR
6+
// RUN: not %clang --target=x86_64-windows-msvc -c -mconsole %s -### 2>&1 | FileCheck %s --check-prefix=ERROR
7+
// RUN: not %clang --target=x86_64-windows-msvc -c -mdll %s -### 2>&1 | FileCheck %s --check-prefix=ERROR
8+
// RUN: not %clang --target=x86_64-windows-msvc -c -mthreads %s -### 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)