Skip to content

Commit aa440aa

Browse files
authored
[flang][Driver] Support -pthread in the frontend (#77360)
The -pthread option seems to be extensively tested for various platforms by clang. Since flang uses those parts of the clang driver, the only test added is to ensure that the option is recognized by the frontend.
1 parent eca25bb commit aa440aa

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5307,7 +5307,8 @@ def pthreads : Flag<["-"], "pthreads">;
53075307
defm pthread : BoolOption<"", "pthread",
53085308
LangOpts<"POSIXThreads">, DefaultFalse,
53095309
PosFlag<SetTrue, [], [ClangOption], "Support POSIX threads in generated code">,
5310-
NegFlag<SetFalse>, BothFlags<[], [ClangOption, CC1Option]>>;
5310+
NegFlag<SetFalse>,
5311+
BothFlags<[], [ClangOption, CC1Option, FlangOption, FC1Option]>>;
53115312
def pie : Flag<["-"], "pie">, Group<Link_Group>;
53125313
def static_pie : Flag<["-"], "static-pie">, Group<Link_Group>;
53135314
def read__only__relocs : Separate<["-"], "read_only_relocs">;

flang/test/Driver/driver-help-hidden.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
! CHECK-NEXT: -pedantic Warn on language extensions
140140
! CHECK-NEXT: -print-effective-triple Print the effective target triple
141141
! CHECK-NEXT: -print-target-triple Print the normalized target triple
142+
! CHECK-NEXT: -pthread Support POSIX threads in generated code
142143
! CHECK-NEXT: -P Disable linemarker output in -E mode
143144
! CHECK-NEXT: -Rpass-analysis=<value> Report transformation analysis from optimization passes whose name matches the given POSIX regular expression
144145
! CHECK-NEXT: -Rpass-missed=<value> Report missed transformations by optimization passes whose name matches the given POSIX regular expression

flang/test/Driver/driver-help.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
! HELP-NEXT: -pedantic Warn on language extensions
126126
! HELP-NEXT: -print-effective-triple Print the effective target triple
127127
! HELP-NEXT: -print-target-triple Print the normalized target triple
128+
! HELP-NEXT: -pthread Support POSIX threads in generated code
128129
! HELP-NEXT: -P Disable linemarker output in -E mode
129130
! HELP-NEXT: -Rpass-analysis=<value> Report transformation analysis from optimization passes whose name matches the given POSIX regular expression
130131
! HELP-NEXT: -Rpass-missed=<value> Report missed transformations by optimization passes whose name matches the given POSIX regular expression
@@ -265,6 +266,7 @@
265266
! HELP-FC1-NEXT: -pic-is-pie File is for a position independent executable
266267
! HELP-FC1-NEXT: -pic-level <value> Value for __PIC__
267268
! HELP-FC1-NEXT: -plugin <name> Use the named plugin action instead of the default action (use "help" to list available options)
269+
! HELP-FC1-NEXT: -pthread Support POSIX threads in generated code
268270
! HELP-FC1-NEXT: -P Disable linemarker output in -E mode
269271
! HELP-FC1-NEXT: -Rpass-analysis=<value> Report transformation analysis from optimization passes whose name matches the given POSIX regular expression
270272
! HELP-FC1-NEXT: -Rpass-missed=<value> Report missed transformations by optimization passes whose name matches the given POSIX regular expression

flang/test/Driver/pthread.f90

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
! In release 2.34, glibc removed libpthread as a separate library. All the
2+
! pthread_* functions were subsumed into libc, so linking that is sufficient.
3+
! However, when linking against older glibc builds, the explicit link of
4+
! -pthread will be required. More details are here:
5+
!
6+
! https://developers.redhat.com/articles/2021/12/17/why-glibc-234-removed-libpthread#the_developer_view
7+
!
8+
! This makes it difficult to write a test that requires the -pthread flag in
9+
! order to pass. Checking for the presence of -lpthread in the linker flags is
10+
! not reliable since the linker could just skip the flag altogether if it is
11+
! linking against a new libc implementation.
12+
13+
! RUN: %flang -### -pthread /dev/null -o /dev/null 2>&1 | FileCheck %s
14+
! RUN: %flang -### -Xflang -pthread /dev/null -o /dev/null 2>&1 | FileCheck %s
15+
16+
! How the -pthread flag is handled is very platform-specific. A lot of that
17+
! functionality is tested by clang, and the flag itself is handled by clang's
18+
! driver that flang also uses. Instead of duplicating all that testing here,
19+
! just check that the presence of the flag does not raise an error. If we need
20+
! more customized handling of -pthread, the tests for that can be added here.
21+
!
22+
! CHECK-NOT: error:

0 commit comments

Comments
 (0)