[clang] [clang][Driver] Make -pthreads an alias to -pthread (PR #213749)
Sam Clegg via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 3 12:46:33 PDT 2026
https://github.com/sbc100 updated https://github.com/llvm/llvm-project/pull/213749
>From 192d1c740365abf4db02e5b12ce0117ddc588926 Mon Sep 17 00:00:00 2001
From: Sam Clegg <sbc at chromium.org>
Date: Mon, 3 Aug 2026 12:30:48 -0700
Subject: [PATCH] [clang][Driver] Make -pthreads an alias to -pthread
Remove `OPT_pthreads` and make `-pthreads` an alias to `-pthread`.
`-pthreads` was originally added in c800391fb9 as a distinct flag.
I believe this is because in GCC it is supported as an alias for
`-pthread` (on Solaris 2 only).
In LLVM this setting is only checked by a subset of toolchains during
linking and is never checked during compilation (`-c`), so it currently
causes `argument unused during compilation: '-pthreads'` (and does
not set `_REENTRANT`). So you could argue that even a Solaris specific
alias it is currently broken.
Aliasing `-pthreads` to `-pthread` makes `-pthreads` work consistently
for both compilation and linking across all targets, and allows removing
`OPT_pthreads` checks in individual toolchains.
Alternatively, if legacy we don't care about Solaris 2 compatibility
we could just drop the `-pthreads` form completely? That option does
have some risk though. This one seems fairly risk-free.
---
clang/include/clang/Options/Options.td | 2 +-
clang/lib/Driver/ToolChains/AIX.cpp | 4 ++--
clang/lib/Driver/ToolChains/Darwin.cpp | 1 -
clang/lib/Driver/ToolChains/Fuchsia.cpp | 2 +-
clang/lib/Driver/ToolChains/Gnu.cpp | 3 +--
clang/lib/Driver/ToolChains/Haiku.cpp | 2 +-
clang/lib/Driver/ToolChains/Solaris.cpp | 1 -
clang/test/Driver/darwin-ld-pthread.c | 2 ++
8 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index 2467ebd0abe19..1cce00d5f8618 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -6674,12 +6674,12 @@ def print_diagnostic_options : Flag<["-", "--"], "print-diagnostic-options">,
HelpText<"Print all of Clang's warning options">,
Visibility<[ClangOption, CLOption]>;
def private__bundle : Flag<["-"], "private_bundle">;
-def pthreads : Flag<["-"], "pthreads">;
defm pthread : BoolOption<"", "pthread",
LangOpts<"POSIXThreads">, DefaultFalse,
PosFlag<SetTrue, [], [ClangOption], "Support POSIX threads in generated code">,
NegFlag<SetFalse>,
BothFlags<[], [ClangOption, CC1Option, FlangOption, FC1Option]>>;
+def : Flag<["-"], "pthreads">, Alias<pthread>;
def static_pie : Flag<["-"], "static-pie">, Group<Link_Group>;
def read__only__relocs : Separate<["-"], "read_only_relocs">;
def remap : Flag<["-"], "remap">;
diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp
index 586bc08067eff..1e449d79a1735 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -312,8 +312,8 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-lpthreads");
}
- // Support POSIX threads if "-pthreads" or "-pthread" is present.
- if (Args.hasArg(options::OPT_pthreads, options::OPT_pthread))
+ // Support POSIX threads if "-pthread" is present.
+ if (Args.hasArg(options::OPT_pthread))
CmdArgs.push_back("-lpthreads");
if (D.CCCIsCXX())
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index d3de04fc5155e..613dec6ef1352 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -807,7 +807,6 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA,
// No need to do anything for pthreads. Claim argument to avoid warning.
Args.ClaimAllArgs(options::OPT_pthread);
- Args.ClaimAllArgs(options::OPT_pthreads);
}
}
diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index abde9fa10482d..19045450cd81c 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -149,7 +149,7 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA,
bool NoLibc = Args.hasArg(options::OPT_nolibc);
bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
!Args.hasArg(options::OPT_static);
- bool Pthreads = Args.hasArg(options::OPT_pthread, options::OPT_pthreads);
+ bool Pthreads = Args.hasArg(options::OPT_pthread);
bool SplitStack = Args.hasArg(options::OPT_fsplit_stack);
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
options::OPT_r)) {
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index 24076d8814322..e0a34295fb513 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -494,8 +494,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
if (NeedsXRayDeps)
linkXRayRuntimeDeps(ToolChain, Args, CmdArgs);
- bool WantPthread = Args.hasArg(options::OPT_pthread) ||
- Args.hasArg(options::OPT_pthreads);
+ bool WantPthread = Args.hasArg(options::OPT_pthread);
// Use the static OpenMP runtime with -static-openmp
bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) &&
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp b/clang/lib/Driver/ToolChains/Haiku.cpp
index a155f22b75a79..10756fda94b44 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -139,7 +139,7 @@ void haiku::Linker::ConstructJob(Compilation &C, const JobAction &JA,
}
// No need to do anything for pthreads. Claim argument to avoid warning.
- Args.claimAllArgs(options::OPT_pthread, options::OPT_pthreads);
+ Args.claimAllArgs(options::OPT_pthread);
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
options::OPT_r)) {
diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp b/clang/lib/Driver/ToolChains/Solaris.cpp
index e5f1cbb033c3b..2b3f5a1307a45 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -119,7 +119,6 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA,
// libpthread has been folded into libc since Solaris 10, no need to do
// anything for pthreads. Claim argument to avoid warning.
Args.ClaimAllArgs(options::OPT_pthread);
- Args.ClaimAllArgs(options::OPT_pthreads);
}
if (LinkerIsGnuLd) {
diff --git a/clang/test/Driver/darwin-ld-pthread.c b/clang/test/Driver/darwin-ld-pthread.c
index b22b68a6e6232..6eddcff45daea 100644
--- a/clang/test/Driver/darwin-ld-pthread.c
+++ b/clang/test/Driver/darwin-ld-pthread.c
@@ -1,4 +1,6 @@
// RUN: %clang -Wunused-command-line-argument -pthread -target x86_64-apple-darwin -### /dev/null -o /dev/null 2>&1 | FileCheck %s
+// RUN: %clang -Wunused-command-line-argument -pthreads -target x86_64-apple-darwin -### /dev/null -o /dev/null 2>&1 | FileCheck %s
// There is nothing to do at link time to get pthread support. But do not warn.
// CHECK-NOT: argument unused during compilation: '-pthread'
+// CHECK-NOT: argument unused during compilation: '-pthreads'
More information about the cfe-commits
mailing list