https://github.com/tarunprabhu updated https://github.com/llvm/llvm-project/pull/77360
>From ab27280e85d6027e6ff119c0803d962753e83b52 Mon Sep 17 00:00:00 2001 From: Tarun Prabhu <ta...@lanl.gov> Date: Mon, 8 Jan 2024 10:56:09 -0700 Subject: [PATCH] [flang][Driver] Support -pthread in the frontend The -pthread option is supported by both clang and gfortran. --- clang/include/clang/Driver/Options.td | 3 ++- flang/test/Driver/driver-help-hidden.f90 | 1 + flang/test/Driver/driver-help.f90 | 2 ++ flang/test/Driver/pthread.f90 | 22 ++++++++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 flang/test/Driver/pthread.f90 diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index d9d6ce81b4d84af..a4a988c71ec412c 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5307,7 +5307,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 a84db70845694e6..426b0e5a1c367d7 100644 --- a/flang/test/Driver/driver-help-hidden.f90 +++ b/flang/test/Driver/driver-help-hidden.f90 @@ -139,6 +139,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 e5cc8a20237651a..221da6439764b4d 100644 --- a/flang/test/Driver/driver-help.f90 +++ b/flang/test/Driver/driver-help.f90 @@ -125,6 +125,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 @@ -265,6 +266,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 000000000000000..6201f4d9f9c2177 --- /dev/null +++ b/flang/test/Driver/pthread.f90 @@ -0,0 +1,22 @@ +! In release 2.34, glibc removed libpthread as a separate library. All the +! pthread_* functions were subsumed into libc, so linking that is sufficient. +! However, when linking against older glibc builds, the explicit link of +! -pthread will be required. More details are here: +! +! https://developers.redhat.com/articles/2021/12/17/why-glibc-234-removed-libpthread#the_developer_view +! +! This makes it difficult to write a test that requires the -pthread flag in +! order to pass. Checking for the presence of -lpthread in the linker flags is +! not reliable since the linker could just skip the flag altogether if it is +! linking against a new libc implementation. + +! 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: _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits