Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -4229,6 +4229,8 @@ 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.">; +def fdebug_module_writer : Flag<["-"],"fdebug-module-writer">, Group, + HelpText<"Enables showing debug messages while writing module files.">; } //===----------------------------------------------------------------------===// Index: clang/lib/Driver/ToolChains/Flang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Flang.cpp +++ clang/lib/Driver/ToolChains/Flang.cpp @@ -35,7 +35,7 @@ } void Flang::AddOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const { - Args.AddAllArgs(CmdArgs, options::OPT_module_dir); + Args.AddAllArgs(CmdArgs, {options::OPT_module_dir,options::OPT_fdebug_module_writer}); } void Flang::ConstructJob(Compilation &C, const JobAction &JA, Index: flang/include/flang/Frontend/CompilerInvocation.h =================================================================== --- flang/include/flang/Frontend/CompilerInvocation.h +++ flang/include/flang/Frontend/CompilerInvocation.h @@ -69,6 +69,8 @@ // of options. std::string moduleDir_ = "."; + bool debugModuleDir_ = false; + // Fortran Dialect options Fortran::common::IntrinsicTypeDefaultKinds defaultKinds_; @@ -91,6 +93,9 @@ std::string &moduleDir() { return moduleDir_; } const std::string &moduleDir() const { return moduleDir_; } + bool &debugModuleDir() { return debugModuleDir_; } + const bool &debugModuleDir() const { return debugModuleDir_; } + Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds() { return defaultKinds_; } Index: flang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- flang/lib/Frontend/CompilerInvocation.cpp +++ flang/lib/Frontend/CompilerInvocation.cpp @@ -227,9 +227,11 @@ /// Parses all semantic related arguments and populates the variables /// options accordingly. -static void parseSemaArgs(std::string &moduleDir, llvm::opt::ArgList &args, +static void parseSemaArgs(CompilerInvocation &res, llvm::opt::ArgList &args, clang::DiagnosticsEngine &diags) { + // -J/module-dir option + auto &moduleDir = res.moduleDir(); auto moduleDirList = args.getAllArgValues(clang::driver::options::OPT_module_dir); // User can only specify -J/-module-dir once @@ -242,6 +244,12 @@ } if (moduleDirList.size() == 1) moduleDir = moduleDirList[0]; + + // -fdebug-module-writer option + auto &debugModuleDir = res.debugModuleDir(); + if (args.hasArg(clang::driver::options::OPT_fdebug_module_writer)) { + debugModuleDir = true; + } } /// Parses all Dialect related arguments and populates the variables @@ -316,7 +324,7 @@ // Parse the preprocessor args parsePreprocessorArgs(res.preprocessorOpts(), args); // Parse semantic args - parseSemaArgs(res.moduleDir(), args, diags); + parseSemaArgs(res, args, diags); // Parse dialect arguments parseDialectArgs(res, args, diags); Index: flang/lib/Frontend/FrontendActions.cpp =================================================================== --- flang/lib/Frontend/FrontendActions.cpp +++ flang/lib/Frontend/FrontendActions.cpp @@ -134,7 +134,7 @@ // Prepare semantics Fortran::semantics::Semantics semantics{ci.invocation().semanticsContext(), - parseTree, ci.parsing().cooked().AsCharBlock()}; + parseTree, ci.parsing().cooked().AsCharBlock(),ci.invocation().debugModuleDir()}; // Run semantic checks semantics.Perform(); Index: flang/test/Semantics/mod-file-rewriter.f90 =================================================================== --- flang/test/Semantics/mod-file-rewriter.f90 +++ flang/test/Semantics/mod-file-rewriter.f90 @@ -3,6 +3,10 @@ ! RUN: %f18 -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED ! RUN: %f18 -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-unchanged.f90 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED ! RUN: %f18 -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-changed.f90 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED +! RUN: %flang-new -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED +! RUN: %flang-new -fsyntax-only -fdebug-module-writer %s 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED +! RUN: %flang-new -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-unchanged.f90 2>&1 | FileCheck %s --check-prefix CHECK_UNCHANGED +! RUN: %flang-new -fsyntax-only -fdebug-module-writer %p/Inputs/mod-file-changed.f90 2>&1 | FileCheck %s --check-prefix CHECK_CHANGED module m real :: x(10)