Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -3548,7 +3548,7 @@ def static_libstdcxx : Flag<["-"], "static-libstdc++">; def static : Flag<["-", "--"], "static">, Group, Flags<[NoArgumentUnused]>; def std_default_EQ : Joined<["-"], "std-default=">; -def std_EQ : Joined<["-", "--"], "std=">, Flags<[CC1Option]>, +def std_EQ : Joined<["-", "--"], "std=">, Flags<[CC1Option,FlangOption,FC1Option]>, Group, HelpText<"Language standard to compile for">, ValuesCode<[{ const char *Values = Index: clang/lib/Driver/ToolChains/Flang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Flang.cpp +++ clang/lib/Driver/ToolChains/Flang.cpp @@ -26,7 +26,8 @@ options::OPT_ffixed_line_length_EQ, options::OPT_fopenmp, options::OPT_fopenacc, options::OPT_fdefault_real_8, options::OPT_fdefault_integer_8, - options::OPT_fdefault_double_8, options::OPT_flarge_sizes}); + options::OPT_fdefault_double_8, options::OPT_flarge_sizes, + options::OPT_std_EQ}); } void Flang::AddPreprocessingOptions(const ArgList &Args, Index: flang/include/flang/Frontend/CompilerInvocation.h =================================================================== --- flang/include/flang/Frontend/CompilerInvocation.h +++ flang/include/flang/Frontend/CompilerInvocation.h @@ -71,6 +71,7 @@ // Fortran Dialect options Fortran::common::IntrinsicTypeDefaultKinds defaultKinds_; + bool standard_ = false; public: CompilerInvocation() = default; @@ -106,6 +107,10 @@ llvm::ArrayRef commandLineArgs, clang::DiagnosticsEngine &diags); + // Enables the std=2018 option + void SetStandard() { + standard_ = true; + } /// Set the Fortran options to predifined defaults. These defaults are /// consistend with f18/f18.cpp. // TODO: We should map frontendOpts_ to parserOpts_ instead. For that, we 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: 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: -I Add 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/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: -I Add 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: -I Add 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/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" +01 end select +end subroutine