[flang-commits] [flang] [clang] [flang][Driver] Support `-pthread` to the frontend. (PR #75739)

Kareem Ergawy via flang-commits flang-commits at lists.llvm.org
Sun Dec 17 06:23:10 PST 2023


https://github.com/ergawy created https://github.com/llvm/llvm-project/pull/75739

Adds `-pthread` option to flang. Since the GNU toolchain already adds the required linker flag, we only need to declare `FlangOption` as one of the supported options for `-pthread`.

>From 2880ebc7f3eec9f0c03747c7a2d92e608b111f3c Mon Sep 17 00:00:00 2001
From: ergawy <kareem.ergawy at amd.com>
Date: Sun, 17 Dec 2023 06:29:49 -0600
Subject: [PATCH] [flang][Driver] Support `-pthread` to the frontend.

Adds `-pthread` option to flang. Since the GNU toolchain already adds
the required linker flag, we only need to declare `FlangOption` as one
of the supported options for `-pthread`.
---
 clang/include/clang/Driver/Options.td | 2 +-
 flang/test/Driver/dynamic-linker.f90  | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 1b02087425b751..b8b8d476413982 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5297,7 +5297,7 @@ 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]>>;
+  NegFlag<SetFalse>, BothFlags<[], [ClangOption, CC1Option, FlangOption]>>;
 def pie : Flag<["-"], "pie">, Group<Link_Group>;
 def static_pie : Flag<["-"], "static-pie">, Group<Link_Group>;
 def read__only__relocs : Separate<["-"], "read_only_relocs">;
diff --git a/flang/test/Driver/dynamic-linker.f90 b/flang/test/Driver/dynamic-linker.f90
index df119c22a2ea51..57a2af01aadff7 100644
--- a/flang/test/Driver/dynamic-linker.f90
+++ b/flang/test/Driver/dynamic-linker.f90
@@ -1,7 +1,7 @@
 ! Verify that certain linker flags are known to the frontend and are passed on
 ! to the linker.
 
-! RUN: %flang -### --target=x86_64-linux-gnu -rpath /path/to/dir -shared \
+! RUN: %flang -### --target=x86_64-linux-gnu -rpath /path/to/dir -shared -pthread \
 ! RUN:     -static %s 2>&1 | FileCheck \
 ! RUN:     --check-prefixes=GNU-LINKER-OPTIONS %s
 ! RUN: %flang -### --target=x86_64-windows-msvc -rpath /path/to/dir -shared \
@@ -13,6 +13,7 @@
 ! GNU-LINKER-OPTIONS-SAME: "-shared"
 ! GNU-LINKER-OPTIONS-SAME: "-static"
 ! GNU-LINKER-OPTIONS-SAME: "-rpath" "/path/to/dir"
+! GNU-LINKER-OPTIONS-SAME: "-lpthread"
 
 ! For MSVC, adding -static does not add any additional linker options.
 ! MSVC-LINKER-OPTIONS: "{{.*}}link{{(.exe)?}}"



More information about the flang-commits mailing list