[clang] [Clang][Driver] Declare win32 threads on Windows (PR #121442)
Mateusz MikuĊa via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 1 14:25:47 PST 2025
https://github.com/mati865 created https://github.com/llvm/llvm-project/pull/121442
Fixes https://github.com/llvm/llvm-project/issues/10148
Recently I saw a user confused by it and thought Clang was using `winpthreads`.
Note: this does not change structures like https://github.com/llvm/llvm-project/blob/0cbe28df7100bf4384f84542d602f90cb783a2d4/clang/include/clang/Basic/LangOptions.h#L360 which still yield `posix`.
>From cc7708f2646326c5065c4853a8a2971db48e3718 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= <mati865 at gmail.com>
Date: Wed, 1 Jan 2025 21:38:49 +0100
Subject: [PATCH] [Clang][Driver] Declare win32 threads on Windows
Fixes https://github.com/llvm/llvm-project/issues/10148
---
clang/include/clang/Driver/ToolChain.h | 8 +++++++-
clang/lib/Driver/ToolChains/Clang.cpp | 2 +-
clang/test/Driver/thread-model.c | 10 +++++++---
3 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h
index 5347e29be91439..9db12486d4d833 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -619,7 +619,13 @@ class ToolChain {
virtual bool SupportsEmbeddedBitcode() const { return false; }
/// getThreadModel() - Which thread model does this target use?
- virtual std::string getThreadModel() const { return "posix"; }
+ virtual std::string getThreadModel() const {
+#ifdef _WIN32
+ return "win32";
+#else
+ return "posix";
+#endif
+ }
/// isThreadModelSupported() - Does this target support a thread model?
virtual bool isThreadModelSupported(const StringRef Model) const;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index a020e00cd17392..bc181dfddc6398 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5792,7 +5792,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
Model = A->getValue();
} else
Model = TC.getThreadModel();
- if (Model != "posix") {
+ if (Model != "posix" && Model != "win32") {
CmdArgs.push_back("-mthread-model");
CmdArgs.push_back(Args.MakeArgString(Model));
}
diff --git a/clang/test/Driver/thread-model.c b/clang/test/Driver/thread-model.c
index 9abe5f11d9aab9..a07f8913630a35 100644
--- a/clang/test/Driver/thread-model.c
+++ b/clang/test/Driver/thread-model.c
@@ -1,5 +1,6 @@
// RUN: %clang -### -target arm-unknown-linux-gnu -c %s -mthread-model posix -v 2>&1 | FileCheck %s
-// RUN: %clang -### -target arm-unknown-linux-gnu -c %s -v 2>&1 | FileCheck %s
+// RUN: %if !system-windows %{ %clang -### -target arm-unknown-linux-gnu -c %s -v 2>&1 | FileCheck %s %}
+// RUN: %if system-windows %{ %clang -### -target arm-unknown-linux-gnu -c %s -v 2>&1 | FileCheck --check-prefix=WIN32 %s %}
// RUN: %clang -### -target arm-unknown-linux-gnu -c %s -mthread-model single -v 2>&1 | FileCheck --check-prefix=SINGLE %s
// RUN: not %clang -target arm-unknown-linux-gnu -c %s -mthread-model silly -v 2>&1 | FileCheck --check-prefix=INVALID %s
@@ -8,9 +9,12 @@
// SINGLE: Thread model: single
// SINGLE: "-mthread-model" "single"
// INVALID: error: invalid thread model 'silly' in '-mthread-model silly' for this target
+// WIN32: Thread model: win32
-// RUN: %clang -### -target wasm32-unknown-linux-gnu -c %s -v 2>&1 | FileCheck %s
+// RUN: %if !system-windows %{ %clang -### -target wasm32-unknown-linux-gnu -c %s -v 2>&1 | FileCheck %s %}
+// RUN: %if system-windows %{ %clang -### -target wasm32-unknown-linux-gnu -c %s -v 2>&1 | FileCheck --check-prefix=WIN32 %s %}
// RUN: %clang -### -target wasm32-unknown-linux-gnu -c %s -v -mthread-model single 2>&1 | FileCheck --check-prefix=SINGLE %s
// RUN: %clang -### -target wasm32-unknown-linux-gnu -c %s -v -mthread-model posix 2>&1 | FileCheck %s
// RUN: not %clang -### --target=wasm32-unknown-linux-gnu -c %s -v -mthread-model silly 2>&1 | FileCheck --check-prefix=INVALID %s
-// RUN: %clang -### -target wasm64-unknown-linux-gnu -c %s -v 2>&1 | FileCheck %s
+// RUN: %if !system-windows %{ %clang -### -target wasm64-unknown-linux-gnu -c %s -v 2>&1 | FileCheck %s %}
+// RUN: %if system-windows %{ %clang -### -target wasm64-unknown-linux-gnu -c %s -v 2>&1 | FileCheck --check-prefix=WIN32 %s %}
More information about the cfe-commits
mailing list