[PATCH] D97119: [flang][driver] Add options for -std=2018

2021-02-26 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 326760.
arnamoy10 added a comment.

1. Updated the test case to include a check when the option is not given and 
make sure works with f18 as well (with `Mstandard`)
2. Changed variable names as suggested.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97119/new/

https://reviews.llvm.org/D97119

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/std2018.f90

Index: flang/test/Flang-Driver/std2018.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/std2018.f90
@@ -0,0 +1,42 @@
+! Ensure argument -std=f2018 works as expected.
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang-new -fsyntax-only -std=f2018 %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: %f18 -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %f18 -fsyntax-only -Mstandard %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: not %flang-new -fsyntax-only -std=90 %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+!  RUN: %flang-new -fc1 %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+!  RUN: %flang-new -fc1 -std=f2018 %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+!  RUN: not %flang-new -fc1 -std=90 %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: A DO loop should terminate with an END DO or CONTINUE
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: A DO loop should terminate with an END DO or CONTINUE
+
+!-
+! EXPECTED OUTPUT WITH WRONG
+!-
+! WRONG: Only -std=2018 is allowed currently.
+
+subroutine foo2()
+do 01 m=1,2
+  select case (m)
+  case default
+print*, "default", m
+  case (1)
+print*, "start"
+01end select
+end subroutine
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -38,6 +38,7 @@
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -o   Write output to 
+! HELP-NEXT: -std=   Language standard to compile for
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
 
@@ -64,6 +65,7 @@
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -o   Write output to 
+! HELP-FC1-NEXT: -std=   Language standard to compile for
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
 
Index: flang/test/Flang-Driver/driver-help-hidden.f90
===
--- flang/test/Flang-Driver/driver-help-hidden.f90
+++ flang/test/Flang-Driver/driver-help-hidden.f90
@@ -38,6 +38,7 @@
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -o  Write output to 
+! CHECK-NEXT: -std=   Language standard to compile for
 ! CHECK-NEXT: -test-io  Run the InputOuputTest action. Use for development and testing only.
 ! CHECK-NEXT: -U  Undefine macro 
 ! CHECK-NEXT: --version Print version information
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -286,6 +286,21 @@
 res.frontendOpts().features_.Enable(
 Fortran::common::LanguageFeature::OpenMP);
   }
+
+  //-std=f2018
+  if (args.hasArg(clang::driver::options::OPT_std_EQ)) {
+auto standard = args.getLastArgValue(clang::driver::options::OPT_std_EQ);
+// We only allow 2018 as the given standard
+if (standard.equals("f2018")) {
+  res.set_EnableConformanceChecks();
+}
+else {
+  const unsigned diagID =
+  diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
+  "Only -std=f2018 is allowed currently.");
+  

[PATCH] D97119: [flang][driver] Add options for -std=2018

2021-02-22 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

Hi @arnamoy10 , thank for working on this!

I suggest making it more explicit that the new option is about _enabling 
standard conformance checks_. So e.g. `enableConformanceChecks` rather than 
`setStandard` (or `set_EnableConformanceChecks` if the member variable is 
called `EnableConformanceChecks`).

I am also mindful that adding `-std=f2018` might be a bit confusing to users if 
we don't support other versions of the language. @tskeith raised this point 
earlier .

Perhaps we should use e..g `-fstd-conf-checks/-fno-std-conf-checks` instead? 
This could be an alias for `-Mstandard` in `f18`. We would replace it with 
`-std=` once that makes more sense.




Comment at: flang/include/flang/Frontend/CompilerInvocation.h:74
   Fortran::common::IntrinsicTypeDefaultKinds defaultKinds_;
+  bool standard_ = false;
 

Wouldn`t e.g. `standardConformanceChecks_` be a bit more self-explanatory? 
Currently this is quite vague.



Comment at: flang/include/flang/Frontend/CompilerInvocation.h:113
+standard_ = true;
+  }
   /// Set the Fortran options to predifined defaults. These defaults are

Missing empty line.



Comment at: flang/test/Flang-Driver/std2018.f90:12-13
+!-
+!  RUN: %flang-new -fc1 -fsyntax-only -std=2018 %s  2>&1 | FileCheck %s 
--check-prefix=GIVEN
+!  RUN: not %flang-new -fc1 -fsyntax-only -std=90 %s  2>&1 | FileCheck %s 
--check-prefix=WRONG
+

[nit] `-fstynax-only` is effectively the default in the frontend driver, see [[ 
https://github.com/llvm/llvm-project/blob/b5b3243bf783f07415c5e2838fa1a948e126f643/flang/lib/Frontend/CompilerInvocation.cpp#L92
 | here ]]. Basically, in the absence of any _action_ options, the driver will 
run the `ParseSyntaxOnly` action (which corresponds to `-fsyntax-only`)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97119/new/

https://reviews.llvm.org/D97119

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97119: [flang][driver] Add options for -std=2018

2021-02-20 Thread Tim Keith via Phabricator via cfe-commits
tskeith added a comment.

Please make sure the test works with f18 also.




Comment at: flang/lib/Frontend/CompilerInvocation.cpp:294
+// We only allow 2018 as the given standard
+if (standard.equals("2018")) {
+  res.SetStandard();

This should be "f2018", not "2018".



Comment at: flang/test/Flang-Driver/std2018.f90:18
+!-
+! GIVEN: A DO loop should terminate with an END DO or CONTINUE
+

Can you verify this message is not produced when there is no -std option?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97119/new/

https://reviews.llvm.org/D97119

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97119: [flang][driver] Add options for -std=2018

2021-02-20 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 created this revision.
arnamoy10 added reviewers: awarzynski, sscalpone, clementval, tskeith.
Herald added subscribers: jansvoboda11, dang.
arnamoy10 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add support for the following Fortran dialect options:

-std=2018

It also adds one test cases.  Currently only `2018` is allowed as the standard.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97119

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/std2018.f90

Index: flang/test/Flang-Driver/std2018.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/std2018.f90
@@ -0,0 +1,33 @@
+! Ensure argument -std=2018 works as expected.
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -fsyntax-only -std=2018 %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: not %flang-new -fsyntax-only -std=90 %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+!  RUN: %flang-new -fc1 -fsyntax-only -std=2018 %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+!  RUN: not %flang-new -fc1 -fsyntax-only -std=90 %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: A DO loop should terminate with an END DO or CONTINUE
+
+!-
+! EXPECTED OUTPUT WITH WRONG
+!-
+! WRONG: Only -std=2018 is allowed currently.
+
+subroutine foo2()
+do 01 m=1,2
+  select case (m)
+  case default
+print*, "default", m
+  case (1)
+print*, "start"
+01end select
+end subroutine
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -38,6 +38,7 @@
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -o   Write output to 
+! HELP-NEXT: -std=   Language standard to compile for
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
 
@@ -64,6 +65,7 @@
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -o   Write output to 
+! HELP-FC1-NEXT: -std=   Language standard to compile for
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
 
Index: flang/test/Flang-Driver/driver-help-hidden.f90
===
--- flang/test/Flang-Driver/driver-help-hidden.f90
+++ flang/test/Flang-Driver/driver-help-hidden.f90
@@ -38,6 +38,7 @@
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -o  Write output to 
+! CHECK-NEXT: -std=   Language standard to compile for
 ! CHECK-NEXT: -test-io  Run the InputOuputTest action. Use for development and testing only.
 ! CHECK-NEXT: -U  Undefine macro 
 ! CHECK-NEXT: --version Print version information
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -286,6 +286,21 @@
 res.frontendOpts().features_.Enable(
 Fortran::common::LanguageFeature::OpenMP);
   }
+
+  //-std=2018
+  if (args.hasArg(clang::driver::options::OPT_std_EQ)) {
+auto standard = args.getLastArgValue(clang::driver::options::OPT_std_EQ);
+// We only allow 2018 as the given standard
+if (standard.equals("2018")) {
+  res.SetStandard();
+}
+else {
+  const unsigned diagID =
+  diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
+  "Only -std=2018 is allowed currently.");
+  diags.Report(diagID);
+}
+  }
   return;
 }
 
@@ -423,6 +438,11 @@
   // directories
   if (moduleDirJ.compare(".") != 0)
 fortranOptions.searchDirectories.emplace_back(moduleDirJ);
+
+  // Set the standard
+  if (standard_) {
+fortranOptions.features.WarnOnAllNonstandard();
+  }
 }
 
 void CompilerInvocation::setSemanticsOpts(
Index: