Skip to content

Commit 4f130fa

Browse files
authored
[flang][Driver] support -fno-openmp (#107087)
Closes #83148
1 parent d77ccae commit 4f130fa

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3545,6 +3545,7 @@ def fopenmp : Flag<["-"], "fopenmp">, Group<f_Group>,
35453545
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
35463546
HelpText<"Parse OpenMP pragmas and generate parallel code.">;
35473547
def fno_openmp : Flag<["-"], "fno-openmp">, Group<f_Group>,
3548+
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
35483549
Flags<[NoArgumentUnused]>;
35493550
class OpenMPVersionHelp<string program, string default> {
35503551
string str = !strconcat(

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,9 @@ static bool parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
968968
/// generated.
969969
static bool parseOpenMPArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
970970
clang::DiagnosticsEngine &diags) {
971-
if (!args.hasArg(clang::driver::options::OPT_fopenmp))
971+
llvm::opt::Arg *arg = args.getLastArg(clang::driver::options::OPT_fopenmp,
972+
clang::driver::options::OPT_fno_openmp);
973+
if (!arg || arg->getOption().matches(clang::driver::options::OPT_fno_openmp))
972974
return true;
973975

974976
unsigned numErrorsBefore = diags.getNumErrors();

flang/test/Driver/fno-openmp.f90

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
! RUN: %flang_fc1 -fopenmp -fno-openmp %s -emit-hlfir -o - | FileCheck --check-prefix=CHECK-NO-OMP %s
2+
! RUN: %flang_fc1 -fno-openmp %s -emit-hlfir -o - | FileCheck --check-prefix=CHECK-NO-OMP %s
3+
! RUN: %flang_fc1 -fno-openmp -fopenmp %s -emit-hlfir -o - | FileCheck --check-prefix=CHECK-OMP %s
4+
! RUN: %flang_fc1 -fopenmp %s -emit-hlfir -o - | FileCheck --check-prefix=CHECK-OMP %s
5+
6+
subroutine main
7+
! CHECK-NO-OMP-NOT: omp.parallel
8+
! CHECK-OMP: omp.parallel
9+
!$omp parallel
10+
print *,"test"
11+
!$omp end parallel
12+
end subroutine

flang/test/Driver/fopenmp.f90

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
! RUN: %flang -target x86_64-windows-gnu -fopenmp=libgomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FC1-NO-OPENMP --check-prefix=CHECK-WARNING
1212
! RUN: %flang -target x86_64-windows-gnu -fopenmp=libiomp5 -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FC1-OPENMP
1313

14+
!RUN: %flang -fno-openmp -fopenmp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FC1-OPENMP
15+
!RUN: %flang -fopenmp -fno-openmp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FC1-NO-OPENMP
16+
1417
! CHECK-FC1-OPENMP: "-fc1"
1518
! CHECK-FC1-OPENMP: "-fopenmp"
1619
!
@@ -59,8 +62,14 @@
5962
! RUN: %flang -target x86_64-freebsd -fopenmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-ANY
6063
! RUN: %flang -target x86_64-windows-gnu -fopenmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-ANYMD
6164
!
65+
! RUN: %flang -target x86_64-linux-gnu -fno-openmp -fopenmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-ANY
66+
! RUN: %flang -target x86_64-linux-gnu -fopenmp -fno-openmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-LD-ANY
67+
!
6268
! CHECK-LD-ANY: "{{.*}}ld{{(.exe)?}}"
6369
! CHECK-LD-ANY: "-l{{(omp|gomp|iomp5)}}"
6470
!
71+
! CHECK-NO-LD-ANY: "{{.*}}ld{{(.exe)?}}"
72+
! CHECK-NO-LD-ANY-NOT: "-l{{(omp|gomp|iomp5)}}"
73+
!
6574
! CHECK-LD-ANYMD: "{{.*}}ld{{(.exe)?}}"
6675
! CHECK-LD-ANYMD: "-l{{(omp|gomp|iomp5md)}}"

0 commit comments

Comments
 (0)