[flang-commits] [flang] [clang] [flang][Driver] Support -pthread in the frontend (PR #77360)

via flang-commits flang-commits at lists.llvm.org
Mon Jan 8 11:09:51 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-driver

Author: Tarun Prabhu (tarunprabhu)

<details>
<summary>Changes</summary>

The -pthread option is supported by both clang and gfortran.

The -pthread option seems to be extensively tested for various platforms by clang. We should be able to piggy-back on those tests since we use the relevant parts of the clang driver. Therefore, the only test added is to ensure that the option is recognized by the frontend.

This has only be tested on x86 Linux.

---
Full diff: https://github.com/llvm/llvm-project/pull/77360.diff


4 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+2-1) 
- (modified) flang/test/Driver/driver-help-hidden.f90 (+1) 
- (modified) flang/test/Driver/driver-help.f90 (+2) 
- (added) flang/test/Driver/pthread.f90 (+10) 


``````````diff
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 6aff37f1336871..3aaf3b58f78f4a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5303,7 +5303,8 @@ 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, FC1Option]>>;
 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/driver-help-hidden.f90 b/flang/test/Driver/driver-help-hidden.f90
index 9a11a7a571ffcc..39c607b80ddb98 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -134,6 +134,7 @@
 ! CHECK-NEXT: -pedantic               Warn on language extensions
 ! CHECK-NEXT: -print-effective-triple Print the effective target triple
 ! CHECK-NEXT: -print-target-triple    Print the normalized target triple
+! CHECK-NEXT: -pthread                Support POSIX threads in generated code
 ! CHECK-NEXT: -P                      Disable linemarker output in -E mode
 ! CHECK-NEXT: -Rpass-analysis=<value> Report transformation analysis from optimization passes whose name matches the given POSIX regular expression
 ! CHECK-NEXT: -Rpass-missed=<value>   Report missed transformations by optimization passes whose name matches the given POSIX regular expression
diff --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90
index e0e74dc56f331e..f00b3ba47e269a 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -120,6 +120,7 @@
 ! HELP-NEXT: -pedantic               Warn on language extensions
 ! HELP-NEXT: -print-effective-triple Print the effective target triple
 ! HELP-NEXT: -print-target-triple    Print the normalized target triple
+! HELP-NEXT: -pthread                Support POSIX threads in generated code
 ! HELP-NEXT: -P                      Disable linemarker output in -E mode
 ! HELP-NEXT: -Rpass-analysis=<value> Report transformation analysis from optimization passes whose name matches the given POSIX regular expression
 ! HELP-NEXT: -Rpass-missed=<value>   Report missed transformations by optimization passes whose name matches the given POSIX regular expression
@@ -258,6 +259,7 @@
 ! HELP-FC1-NEXT: -pic-is-pie             File is for a position independent executable
 ! HELP-FC1-NEXT: -pic-level <value>      Value for __PIC__
 ! HELP-FC1-NEXT: -plugin <name>          Use the named plugin action instead of the default action (use "help" to list available options)
+! HELP-FC1-NEXT: -pthread                Support POSIX threads in generated code
 ! HELP-FC1-NEXT: -P                      Disable linemarker output in -E mode
 ! HELP-FC1-NEXT: -Rpass-analysis=<value> Report transformation analysis from optimization passes whose name matches the given POSIX regular expression
 ! HELP-FC1-NEXT: -Rpass-missed=<value>   Report missed transformations by optimization passes whose name matches the given POSIX regular expression
diff --git a/flang/test/Driver/pthread.f90 b/flang/test/Driver/pthread.f90
new file mode 100644
index 00000000000000..e3fd392ed91aff
--- /dev/null
+++ b/flang/test/Driver/pthread.f90
@@ -0,0 +1,10 @@
+! RUN: %flang -### -pthread /dev/null -o /dev/null 2>&1 | FileCheck %s
+! RUN: %flang -### -Xflang -pthread /dev/null -o /dev/null 2>&1 | FileCheck %s
+
+! How the -pthread flag is handled is very platform-specific. A lot of that
+! functionality is tested by clang, and the flag itself is handled by clang's
+! driver that flang also uses. Instead of duplicating all that testing here,
+! just check that the presence of the flag does not raise an error. If we need
+! more customized handling of -pthread, the tests for that can be added here.
+!
+! CHECK-NOT: error:

``````````

</details>


https://github.com/llvm/llvm-project/pull/77360


More information about the flang-commits mailing list