Skip to content

Commit b4a5daa

Browse files
committed
[Clang][Driver] Declare win32 threads on Windows
Fixes #101
1 parent fa56e8b commit b4a5daa

File tree

5 files changed

+12
-2
lines changed

5 files changed

+12
-2
lines changed

clang/lib/Driver/ToolChain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ bool ToolChain::isThreadModelSupported(const StringRef Model) const {
10821082
Triple.getArch() == llvm::Triple::armeb ||
10831083
Triple.getArch() == llvm::Triple::thumb ||
10841084
Triple.getArch() == llvm::Triple::thumbeb || Triple.isWasm();
1085-
} else if (Model == "posix")
1085+
} else if (Model == "posix" || (Model == "win32" && Triple.isOSWindows()))
10861086
return true;
10871087

10881088
return false;

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5792,7 +5792,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
57925792
Model = A->getValue();
57935793
} else
57945794
Model = TC.getThreadModel();
5795-
if (Model != "posix") {
5795+
if (Model != "posix" && Model != "win32") {
57965796
CmdArgs.push_back("-mthread-model");
57975797
CmdArgs.push_back(Args.MakeArgString(Model));
57985798
}

clang/lib/Driver/ToolChains/MSVC.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain {
5151
TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
5252
Action::OffloadKind DeviceOffloadKind) const override;
5353

54+
std::string getThreadModel() const override { return "win32"; }
55+
5456
UnwindTableLevel
5557
getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const override;
5658
bool isPICDefault() const override;

clang/lib/Driver/ToolChains/MinGW.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class LLVM_LIBRARY_VISIBILITY MinGW : public ToolChain {
6666

6767
bool HasNativeLLVMSupport() const override;
6868

69+
std::string getThreadModel() const override { return "win32"; }
70+
6971
UnwindTableLevel
7072
getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const override;
7173
bool isPICDefault() const override;

clang/test/Driver/thread-model.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@
88
// SINGLE: Thread model: single
99
// SINGLE: "-mthread-model" "single"
1010
// INVALID: error: invalid thread model 'silly' in '-mthread-model silly' for this target
11+
// WIN32: Thread model: win32
1112

1213
// RUN: %clang -### -target wasm32-unknown-linux-gnu -c %s -v 2>&1 | FileCheck %s
1314
// RUN: %clang -### -target wasm32-unknown-linux-gnu -c %s -v -mthread-model single 2>&1 | FileCheck --check-prefix=SINGLE %s
1415
// RUN: %clang -### -target wasm32-unknown-linux-gnu -c %s -v -mthread-model posix 2>&1 | FileCheck %s
1516
// RUN: not %clang -### --target=wasm32-unknown-linux-gnu -c %s -v -mthread-model silly 2>&1 | FileCheck --check-prefix=INVALID %s
1617
// RUN: %clang -### -target wasm64-unknown-linux-gnu -c %s -v 2>&1 | FileCheck %s
18+
19+
// RUN: %clang -### -target x86_64-pc-windows-gnu -c %s -v 2>&1 | FileCheck --check-prefix=WIN32 %s
20+
// RUN: %clang -### -target x86_64-pc-windows-gnu -c %s -v -mthread-model posix 2>&1 | FileCheck %s
21+
// RUN: %clang -### -target x86_64-pc-windows-gnu -c %s -v -mthread-model win32 2>&1 | FileCheck --check-prefix=WIN32 %s
22+
// RUN: %clang -### -target x86_64-pc-windows-msvc -c %s -v 2>&1 | FileCheck --check-prefix=WIN32 %s

0 commit comments

Comments
 (0)