Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -4342,6 +4342,8 @@ def fno_implicit_none : Flag<["-"], "fno-implicit-none">, Group; def falternative_parameter_statement : Flag<["-"], "falternative-parameter-statement">, Group, HelpText<"Enable the old style PARAMETER statement">; +def werror : Flag<["-"], "Werror">, Group, + HelpText<"Make all warnings into errors">; } //===----------------------------------------------------------------------===// Index: clang/lib/Driver/ToolChains/Flang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Flang.cpp +++ clang/lib/Driver/ToolChains/Flang.cpp @@ -42,7 +42,8 @@ void Flang::AddOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const { Args.AddAllArgs(CmdArgs, - {options::OPT_module_dir, options::OPT_fdebug_module_writer}); + {options::OPT_module_dir, options::OPT_fdebug_module_writer, + options::OPT_werror}); } 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 @@ -71,6 +71,8 @@ bool debugModuleDir_ = false; + bool warnAsErr_ = false; + // Fortran Dialect options Fortran::common::IntrinsicTypeDefaultKinds defaultKinds_; @@ -96,6 +98,9 @@ bool &debugModuleDir() { return debugModuleDir_; } const bool &debugModuleDir() const { return debugModuleDir_; } + bool &warnAsErr() { return warnAsErr_; } + const bool &warnAsErr() const { return warnAsErr_; } + Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds() { return defaultKinds_; } @@ -116,6 +121,8 @@ void SetDebugModuleDir(bool flag) { debugModuleDir_ = flag; } + void SetWarnAsErr(bool flag) { warnAsErr_ = flag; } + /// 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 @@ -327,6 +327,11 @@ if (args.hasArg(clang::driver::options::OPT_fdebug_module_writer)) { res.SetDebugModuleDir(true); } + + // -Werror option + if (args.hasArg(clang::driver::options::OPT_werror)) { + res.SetWarnAsErr(true); + } } /// Parses all Dialect related arguments and populates the variables @@ -518,5 +523,6 @@ defaultKinds(), fortranOptions.features, allCookedSources); semanticsContext_->set_moduleDirectory(moduleDir()) - .set_searchDirectories(fortranOptions.searchDirectories); + .set_searchDirectories(fortranOptions.searchDirectories) + .set_warningsAreErrors(warnAsErr()); } Index: flang/test/Semantics/dosemantics03.f90 =================================================================== --- flang/test/Semantics/dosemantics03.f90 +++ flang/test/Semantics/dosemantics03.f90 @@ -1,4 +1,5 @@ ! RUN: %S/test_errors.sh %s %t %f18 -Mstandard -Werror +! RUN: %S/test_errors.sh %s %t %flang_fc1 -Werror ! Issue 458 -- semantic checks for a normal DO loop. The DO variable ! and the initial, final, and step expressions must be INTEGER if the