arnamoy10 updated this revision to Diff 323480.
arnamoy10 edited the summary of this revision.
arnamoy10 added a comment.
Addressing reviewers' comments.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D96344/new/
https://reviews.llvm.org/D96344
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/fdefault.f90
flang/test/Flang-Driver/pipeline.f90
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"
+
Index: flang/test/Flang-Driver/fdefault.f90
===================================================================
--- /dev/null
+++ flang/test/Flang-Driver/fdefault.f90
@@ -0,0 +1,26 @@
+! Ensure argument -fdefault* works as expected.
+! TODO: Add checks when actual codegen is possible for this family
+
+! REQUIRES: new-flang-driver
+
+!--------------------------
+! FLANG DRIVER (flang-new)
+!--------------------------
+! RUN: not %flang-new -fsyntax-only -fdefault-double-8 %s 2>&1 | FileCheck %s --check-prefix=DOUBLE
+
+!-----------------------------------------
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-----------------------------------------
+! RUN: not %flang-new -fc1 -fsyntax-only -fdefault-double-8 %s 2>&1 | FileCheck %s --check-prefix=DOUBLE
+
+!-----------------------------------------
+! EXPECTED OUTPUT FOR PROVIDING ONLY -fdefault-double-8
+!-----------------------------------------
+! DOUBLE:error: Use of `-fdefault-double-8` requires `-fdefault-real-8`
+
+PROGRAM test
+ implicit none
+ real :: x ! note kind is not specified
+ x = 3.4
+ print *, "x = ", x
+END PROGRAM
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 <macro>=<value> Define <macro> to <value> (or 1 if <value> 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=<value>
-! HELP-NEXT: Use <value> as character line width in fixed mode
+! HELP-NEXT: Use <value> as character line width in fixed mode
! HELP-NEXT: -ffree-form Process source files in free form
+! HELP-NEXT: -flarge-sizes Set the default KIND for INTEGER to 8.
! 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 <macro>=<value> Define <macro> to <value> (or 1 if <value> 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=<value>
! HELP-FC1-NEXT: Use <value> as character line width in fixed mode
! HELP-FC1-NEXT: -ffree-form Process source files in free form
+! HELP-FC1-NEXT: -flarge-sizes Set the default KIND for INTEGER to 8.
! 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/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 <macro>=<value> Define <macro> to <value> (or 1 if <value> 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=<value>
! CHECK-NEXT: Use <value> as character line width in fixed mode
! CHECK-NEXT: -ffree-form Process source files in free form
+! CHECK-NEXT: -flarge-sizes Set the default KIND for INTEGER to 8.
! 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/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,45 @@
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);
+ 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);
+ }
+ res.defaultKinds().set_defaultRealKind(4);
+ }
+ 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<const char *> commandLineArgs,
clang::DiagnosticsEngine &diags) {
@@ -282,6 +314,8 @@
parsePreprocessorArgs(res.preprocessorOpts(), args);
// Parse semantic args
parseSemaArgs(res.moduleDir(), args, diags);
+ // Parse dialect arguments
+ parseDialectArgs(res, args, diags);
return success;
}
@@ -390,8 +424,7 @@
const auto &fortranOptions = fortranOpts();
semanticsContext_ = std::make_unique<semantics::SemanticsContext>(
- *(new Fortran::common::IntrinsicTypeDefaultKinds()),
- fortranOptions.features, allCookedSources);
+ defaultKinds(), fortranOptions.features, allCookedSources);
auto &moduleDirJ = moduleDir();
semanticsContext_->set_moduleDirectory(moduleDirJ)
Index: flang/include/flang/Frontend/CompilerInvocation.h
===================================================================
--- flang/include/flang/Frontend/CompilerInvocation.h
+++ flang/include/flang/Frontend/CompilerInvocation.h
@@ -69,6 +69,10 @@
// of options.
std::string moduleDir_ = ".";
+ // Fortran Dialect options
+ std::unique_ptr<Fortran::common::IntrinsicTypeDefaultKinds> defaultKinds_ =
+ std::make_unique<Fortran::common::IntrinsicTypeDefaultKinds>();
+
public:
CompilerInvocation() = default;
@@ -88,6 +92,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: 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: 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<gfortran_Group>;
defm d_lines_as_code : BooleanFFlag<"d-lines-as-code">, Group<gfortran_Group>;
defm d_lines_as_comments : BooleanFFlag<"d-lines-as-comments">, Group<gfortran_Group>;
-defm default_double_8 : BooleanFFlag<"default-double-8">, Group<gfortran_Group>;
-defm default_integer_8 : BooleanFFlag<"default-integer-8">, Group<gfortran_Group>;
-defm default_real_8 : BooleanFFlag<"default-real-8">, Group<gfortran_Group>;
defm dollar_ok : BooleanFFlag<"dollar-ok">, Group<gfortran_Group>;
defm dump_fortran_optimized : BooleanFFlag<"dump-fortran-optimized">, Group<gfortran_Group>;
defm dump_fortran_original : BooleanFFlag<"dump-fortran-original">, Group<gfortran_Group>;
@@ -4224,7 +4221,14 @@
def ffixed_line_length_VALUE : Joined<["-"], "ffixed-line-length-">, Group<f_Group>, Alias<ffixed_line_length_EQ>;
def fopenacc : Flag<["-"], "fopenacc">, Group<f_Group>,
HelpText<"Enable OpenACC">;
-
+def fdefault_double_8 : Flag<["-"],"fdefault-double-8">, Group<f_Group>, Flags<[FlangOption,FC1Option,FlangOnlyOption]>,
+ 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<f_Group>, Flags<[FlangOption,FC1Option,FlangOnlyOption]>,
+ HelpText<"Set the default integer and logical types to an 8 byte wide type.">;
+def fdefault_real_8 : Flag<["-"],"fdefault-real-8">, Group<f_Group>, Flags<[FlangOption,FC1Option,FlangOnlyOption]>,
+ HelpText<"Set the default real type to an 8 byte wide type.">;
+def flarge_sizes : Flag<["-"],"flarge-sizes">, Group<f_Group>, Flags<[FlangOption,FC1Option,FlangOnlyOption]>,
+ HelpText<"Set the default KIND for INTEGER to 8.">;
}
//===----------------------------------------------------------------------===//
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits