Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -4160,9 +4160,6 @@ defm cray_pointer : BooleanFFlag<"cray-pointer">, Group; defm d_lines_as_code : BooleanFFlag<"d-lines-as-code">, Group; defm d_lines_as_comments : BooleanFFlag<"d-lines-as-comments">, Group; -defm default_double_8 : BooleanFFlag<"default-double-8">, Group; -defm default_integer_8 : BooleanFFlag<"default-integer-8">, Group; -defm default_real_8 : BooleanFFlag<"default-real-8">, Group; defm dollar_ok : BooleanFFlag<"dollar-ok">, Group; defm dump_fortran_optimized : BooleanFFlag<"dump-fortran-optimized">, Group; defm dump_fortran_original : BooleanFFlag<"dump-fortran-original">, Group; @@ -4224,7 +4221,14 @@ def ffixed_line_length_VALUE : Joined<["-"], "ffixed-line-length-">, Group, Alias; def fopenacc : Flag<["-"], "fopenacc">, Group, HelpText<"Enable OpenACC">; - +def fdefault_double_8 : Flag<["-"],"fdefault-double-8">, Group, + HelpText<"Set the DOUBLE PRECISION type and double real constants like 1.d0 to an 8 byte wide type.">; +def fdefault_integer_8 : Flag<["-"],"fdefault-integer-8">, Group, + HelpText<"Set the default integer and logical types to an 8 byte wide type.">; +def fdefault_real_8 : Flag<["-"],"fdefault-real-8">, Group, + HelpText<"Set the default real type to an 8 byte wide type.">; +def flarge_sizes : Flag<["-"],"flarge-sizes">, Group, + HelpText<"Use INTEGER(KIND=8) for the result type in size-related intrinsics.">; } //===----------------------------------------------------------------------===// Index: clang/lib/Driver/ToolChains/Flang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Flang.cpp +++ clang/lib/Driver/ToolChains/Flang.cpp @@ -21,9 +21,12 @@ void Flang::AddFortranDialectOptions(const ArgList &Args, ArgStringList &CmdArgs) const { - Args.AddAllArgs(CmdArgs, {options::OPT_ffixed_form, options::OPT_ffree_form, - options::OPT_ffixed_line_length_EQ, - options::OPT_fopenmp, options::OPT_fopenacc}); + Args.AddAllArgs(CmdArgs, + {options::OPT_ffixed_form, options::OPT_ffree_form, + 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}); } 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 @@ -69,6 +69,9 @@ // of options. std::string moduleDir_ = "."; + // Fortran Dialect options + Fortran::common::IntrinsicTypeDefaultKinds defaultKinds_; + public: CompilerInvocation() = default; @@ -88,6 +91,13 @@ std::string &moduleDir() { return moduleDir_; } const std::string &moduleDir() const { return moduleDir_; } + Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds() { + return defaultKinds_; + } + const Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds() const { + return defaultKinds_; + } + /// Create a compiler invocation from a list of input options. /// \returns true on success. /// \returns false if an error was encountered while parsing the arguments Index: flang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- flang/lib/Frontend/CompilerInvocation.cpp +++ flang/lib/Frontend/CompilerInvocation.cpp @@ -200,13 +200,6 @@ } } - // Extensions - if (args.hasArg(clang::driver::options::OPT_fopenacc)) { - opts.features_.Enable(Fortran::common::LanguageFeature::OpenACC); - } - if (args.hasArg(clang::driver::options::OPT_fopenmp)) { - opts.features_.Enable(Fortran::common::LanguageFeature::OpenMP); - } return dashX; } @@ -251,6 +244,51 @@ moduleDir = moduleDirList[0]; } +/// Parses all Dialect related arguments and populates the variables +/// options accordingly. +static void parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args, + clang::DiagnosticsEngine &diags) { + + // -fdefault* family + if (args.hasArg(clang::driver::options::OPT_fdefault_real_8)) { + res.defaultKinds().set_defaultRealKind(8); + res.defaultKinds().set_doublePrecisionKind(16); + } + if (args.hasArg(clang::driver::options::OPT_fdefault_integer_8)) { + res.defaultKinds().set_defaultIntegerKind(8); + res.defaultKinds().set_subscriptIntegerKind(8); + res.defaultKinds().set_sizeIntegerKind(8); + } + if (args.hasArg(clang::driver::options::OPT_fdefault_double_8)) { + if (!args.hasArg(clang::driver::options::OPT_fdefault_real_8)) { + // -fdefault-double-8 has to be used with -fdefault-real-8 + // to be compatible with gfortran + const unsigned diagID = + diags.getCustomDiagID(clang::DiagnosticsEngine::Error, + "Use of `-fdefault-double-8` requires `-fdefault-real-8`"); + diags.Report(diagID); + } + // For -fdefault-double-8 + -fdefault-real-8, only the size of + // DOUBLE PRECISION type changes, the size of default real type stays + // the same + // https://gcc.gnu.org/onlinedocs/gfortran/Fortran-Dialect-Options.html + res.defaultKinds().set_doublePrecisionKind(8); + } + if (args.hasArg(clang::driver::options::OPT_flarge_sizes)) + res.defaultKinds().set_sizeIntegerKind(8); + + // -fopenmp and -fopenacc + if (args.hasArg(clang::driver::options::OPT_fopenacc)) { + res.frontendOpts().features_.Enable( + Fortran::common::LanguageFeature::OpenACC); + } + if (args.hasArg(clang::driver::options::OPT_fopenmp)) { + res.frontendOpts().features_.Enable( + Fortran::common::LanguageFeature::OpenMP); + } + return; +} + bool CompilerInvocation::CreateFromArgs(CompilerInvocation &res, llvm::ArrayRef commandLineArgs, clang::DiagnosticsEngine &diags) { @@ -282,6 +320,8 @@ parsePreprocessorArgs(res.preprocessorOpts(), args); // Parse semantic args parseSemaArgs(res.moduleDir(), args, diags); + // Parse dialect arguments + parseDialectArgs(res, args, diags); return success; } @@ -390,8 +430,7 @@ const auto &fortranOptions = fortranOpts(); semanticsContext_ = std::make_unique( - *(new Fortran::common::IntrinsicTypeDefaultKinds()), - fortranOptions.features, allCookedSources); + defaultKinds(), fortranOptions.features, allCookedSources); auto &moduleDirJ = moduleDir(); semanticsContext_->set_moduleDirectory(moduleDirJ) 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 @@ -23,10 +23,14 @@ ! CHECK-NEXT: -D = Define to (or 1 if omitted) ! CHECK-NEXT: -E Only run the preprocessor ! CHECK-NEXT: -fcolor-diagnostics Enable colors in diagnostics +! CHECK-NEXT: -fdefault-double-8 Set the DOUBLE PRECISION type and double real constants like 1.d0 to an 8 byte wide type. +! CHECK-NEXT: -fdefault-integer-8 Set the default integer and logical types to an 8 byte wide type. +! CHECK-NEXT: -fdefault-real-8 Set the default real type to an 8 byte wide type. ! CHECK-NEXT: -ffixed-form Process source files in fixed form ! CHECK-NEXT: -ffixed-line-length= ! CHECK-NEXT: Use as character line width in fixed mode ! CHECK-NEXT: -ffree-form Process source files in free form +! CHECK-NEXT: -flarge-sizes Use INTEGER(KIND=8) for the result type in size-related intrinsics. ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics ! CHECK-NEXT: -fopenacc Enable OpenACC ! CHECK-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. Index: flang/test/Flang-Driver/driver-help.f90 =================================================================== --- flang/test/Flang-Driver/driver-help.f90 +++ flang/test/Flang-Driver/driver-help.f90 @@ -23,10 +23,14 @@ ! HELP-NEXT: -D = Define to (or 1 if omitted) ! HELP-NEXT: -E Only run the preprocessor ! HELP-NEXT: -fcolor-diagnostics Enable colors in diagnostics +! HELP-NEXT: -fdefault-double-8 Set the DOUBLE PRECISION type and double real constants like 1.d0 to an 8 byte wide type. +! HELP-NEXT: -fdefault-integer-8 Set the default integer and logical types to an 8 byte wide type. +! HELP-NEXT: -fdefault-real-8 Set the default real type to an 8 byte wide type. ! HELP-NEXT: -ffixed-form Process source files in fixed form ! HELP-NEXT: -ffixed-line-length= ! HELP-NEXT: Use as character line width in fixed mode ! HELP-NEXT: -ffree-form Process source files in free form +! HELP-NEXT: -flarge-sizes Use INTEGER(KIND=8) for the result type in size-related intrinsics. ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics ! HELP-NEXT: -fopenacc Enable OpenACC ! HELP-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. @@ -46,10 +50,14 @@ ! HELP-FC1-NEXT: -D = Define to (or 1 if omitted) ! HELP-FC1-NEXT: -emit-obj Emit native object files ! HELP-FC1-NEXT: -E Only run the preprocessor +! HELP-FC1-NEXT: -fdefault-double-8 Set the DOUBLE PRECISION type and double real constants like 1.d0 to an 8 byte wide type. +! HELP-FC1-NEXT: -fdefault-integer-8 Set the default integer and logical types to an 8 byte wide type. +! HELP-FC1-NEXT: -fdefault-real-8 Set the default real type to an 8 byte wide type. ! HELP-FC1-NEXT: -ffixed-form Process source files in fixed form ! HELP-FC1-NEXT: -ffixed-line-length= ! HELP-FC1-NEXT: Use as character line width in fixed mode ! HELP-FC1-NEXT: -ffree-form Process source files in free form +! HELP-FC1-NEXT: -flarge-sizes Use INTEGER(KIND=8) for the result type in size-related intrinsics. ! HELP-FC1-NEXT: -fopenacc Enable OpenACC ! HELP-FC1-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. ! HELP-FC1-NEXT: -help Display available options Index: flang/test/Flang-Driver/fdefault.f90 =================================================================== --- /dev/null +++ flang/test/Flang-Driver/fdefault.f90 @@ -0,0 +1,62 @@ +! Ensure argument -fdefault* work as expected. +! TODO: Add checks when actual codegen is possible for this family +! REQUIRES: new-flang-driver + +!-------------------------- +! FLANG DRIVER (flang-new) +!-------------------------- +! RUN: rm -rf %t/dir-flang-new && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -module-dir %t/dir-flang-new %s 2>&1 +! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=NOOPTION +! RUN: rm -rf %t/dir-flang-new && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -fdefault-real-8 -module-dir %t/dir-flang-new %s 2>&1 +! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=REAL8 +! RUN: rm -rf %t/dir-flang-new && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -fdefault-real-8 -fdefault-double-8 -module-dir %t/dir-flang-new %s 2>&1 +! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=DOUBLE8 +! RUN: not %flang -fsyntax-only -fdefault-double-8 %s 2>&1 | FileCheck %s --check-prefix=ERROR + +!----------------------------------------- +! FRONTEND FLANG DRIVER (flang-new -fc1) +!----------------------------------------- +! RUN: rm -rf %t/dir-flang-new && mkdir -p %t/dir-flang-new && %flang -fc1 -fsyntax-only -module-dir %t/dir-flang-new %s 2>&1 +! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=NOOPTION +! RUN: rm -rf %t/dir-flang-new && mkdir -p %t/dir-flang-new && %flang -fc1 -fsyntax-only -fdefault-real-8 -module-dir %t/dir-flang-new %s 2>&1 +! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=REAL8 +! RUN: rm -rf %t/dir-flang-new && mkdir -p %t/dir-flang-new && %flang -fc1 -fsyntax-only -fdefault-real-8 -fdefault-double-8 -module-dir %t/dir-flang-new %s 2>&1 +! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=DOUBLE8 +! RUN: not %flang -fc1 -fsyntax-only -fdefault-double-8 %s 2>&1 | FileCheck %s --check-prefix=ERROR + + + + +!----------------------------------------- +! EXPECTED OUTPUT FOR NO SPECIFICATION +!----------------------------------------- +! NOOPTION: integer(4),parameter::real_kind=4_4 +! NOOPTION-NEXT: intrinsic::kind +! NOOPTION-NEXT: integer(4),parameter::double_kind=8_4 + +!----------------------------------------- +! EXPECTED OUTPUT FOR ONLY -fdefault-real-8 +!----------------------------------------- +! REAL8: integer(4),parameter::real_kind=8_4 +! REAL8-NEXT: intrinsic::kind +! REAL8-NEXT: integer(4),parameter::double_kind=16_4 + +!----------------------------------------- +! EXPECTED OUTPUT FOR -fdefault-real-8 AND -fdefault-double-8 +!----------------------------------------- +! DOUBLE8: integer(4),parameter::real_kind=8_4 +! DOUBLE8-NEXT: intrinsic::kind +! DOUBLE8-NEXT: integer(4),parameter::double_kind=8_4 + +!----------------------------------------- +! EXPECTED OUTPUT FOR PROVIDING ONLY -fdefault-double-8 +!----------------------------------------- +! ERROR: error: Use of `-fdefault-double-8` requires `-fdefault-real-8` + +module m + implicit none + real :: x + double precision :: y + integer, parameter :: real_kind = kind(x) !-fdefault-real-8 + integer, parameter :: double_kind = kind(y) !-fdefault-double-8 +end Index: flang/test/Flang-Driver/flarge_sizes.f90 =================================================================== --- /dev/null +++ flang/test/Flang-Driver/flarge_sizes.f90 @@ -0,0 +1,27 @@ +! Ensure argument -flarge-sizes works as expected. +! TODO: Add checks when actual codegen is possible for this family +! REQUIRES: new-flang-driver + +!-------------------------- +! FLANG DRIVER (flang-new) +!-------------------------- +! RUN: rm -rf %t/dir-flang-new && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -flarge-sizes -module-dir %t/dir-flang-new %s 2>&1 +! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=LARGE + +!----------------------------------------- +! FRONTEND FLANG DRIVER (flang-new -fc1) +!----------------------------------------- +! RUN: rm -rf %t/dir-flang-new && mkdir -p %t/dir-flang-new && %flang -fc1 -fsyntax-only -flarge-sizes -module-dir %t/dir-flang-new %s 2>&1 +! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=LARGE + +!----------------------------------------- +! EXPECTED OUTPUT FOR -flarge-sizes +!----------------------------------------- +! LARGE: real(4)::z(1_8:10_8) +! LARGE-NEXT: integer(4),parameter::size_kind=8_4 + +module m + implicit none + real :: z(10) + integer, parameter :: size_kind = kind(ubound(z, 1)) !-flarge-sizes +end Index: flang/test/Flang-Driver/pipeline.f90 =================================================================== --- /dev/null +++ flang/test/Flang-Driver/pipeline.f90 @@ -0,0 +1,17 @@ +! This file tests that flang-new forwards +! all Flang frontend options to flang-new -fc1 +! as expected. +! +! RUN: %flang-new -fsyntax-only -### %s -o %t 2>&1 \ +! RUN: -fdefault-double-8 \ +! RUN: -fdefault-integer-8 \ +! RUN: -fdefault-real-8 \ +! RUN: -flarge-sizes \ +! RUN: | FileCheck %s +! +! +! CHECK: "-fdefault-double-8" +! CHECK: "-fdefault-integer-8" +! CHECK: "-fdefault-real-8" +! CHECK: "-flarge-sizes" +