Skip to content

Commit

Permalink
[flang][Driver] support -fno-openmp (#107087)
Browse files Browse the repository at this point in the history
Closes #83148
  • Loading branch information
tblah authored Sep 4, 2024
1 parent d77ccae commit 4f130fa
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -3545,6 +3545,7 @@ def fopenmp : Flag<["-"], "fopenmp">, Group<f_Group>,
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
HelpText<"Parse OpenMP pragmas and generate parallel code.">;
def fno_openmp : Flag<["-"], "fno-openmp">, Group<f_Group>,
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
Flags<[NoArgumentUnused]>;
class OpenMPVersionHelp<string program, string default> {
string str = !strconcat(
Expand Down
4 changes: 3 additions & 1 deletion flang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,9 @@ static bool parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
/// generated.
static bool parseOpenMPArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
clang::DiagnosticsEngine &diags) {
if (!args.hasArg(clang::driver::options::OPT_fopenmp))
llvm::opt::Arg *arg = args.getLastArg(clang::driver::options::OPT_fopenmp,
clang::driver::options::OPT_fno_openmp);
if (!arg || arg->getOption().matches(clang::driver::options::OPT_fno_openmp))
return true;

unsigned numErrorsBefore = diags.getNumErrors();
Expand Down
12 changes: 12 additions & 0 deletions flang/test/Driver/fno-openmp.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
! RUN: %flang_fc1 -fopenmp -fno-openmp %s -emit-hlfir -o - | FileCheck --check-prefix=CHECK-NO-OMP %s
! RUN: %flang_fc1 -fno-openmp %s -emit-hlfir -o - | FileCheck --check-prefix=CHECK-NO-OMP %s
! RUN: %flang_fc1 -fno-openmp -fopenmp %s -emit-hlfir -o - | FileCheck --check-prefix=CHECK-OMP %s
! RUN: %flang_fc1 -fopenmp %s -emit-hlfir -o - | FileCheck --check-prefix=CHECK-OMP %s

subroutine main
! CHECK-NO-OMP-NOT: omp.parallel
! CHECK-OMP: omp.parallel
!$omp parallel
print *,"test"
!$omp end parallel
end subroutine
9 changes: 9 additions & 0 deletions flang/test/Driver/fopenmp.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
! 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
! RUN: %flang -target x86_64-windows-gnu -fopenmp=libiomp5 -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FC1-OPENMP

!RUN: %flang -fno-openmp -fopenmp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FC1-OPENMP
!RUN: %flang -fopenmp -fno-openmp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FC1-NO-OPENMP

! CHECK-FC1-OPENMP: "-fc1"
! CHECK-FC1-OPENMP: "-fopenmp"
!
Expand Down Expand Up @@ -59,8 +62,14 @@
! RUN: %flang -target x86_64-freebsd -fopenmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-ANY
! RUN: %flang -target x86_64-windows-gnu -fopenmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-ANYMD
!
! RUN: %flang -target x86_64-linux-gnu -fno-openmp -fopenmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-ANY
! RUN: %flang -target x86_64-linux-gnu -fopenmp -fno-openmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-LD-ANY
!
! CHECK-LD-ANY: "{{.*}}ld{{(.exe)?}}"
! CHECK-LD-ANY: "-l{{(omp|gomp|iomp5)}}"
!
! CHECK-NO-LD-ANY: "{{.*}}ld{{(.exe)?}}"
! CHECK-NO-LD-ANY-NOT: "-l{{(omp|gomp|iomp5)}}"
!
! CHECK-LD-ANYMD: "{{.*}}ld{{(.exe)?}}"
! CHECK-LD-ANYMD: "-l{{(omp|gomp|iomp5md)}}"

0 comments on commit 4f130fa

Please sign in to comment.