Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -740,7 +740,7 @@ MarshallingInfoStringVector>; def Wwrite_strings : Flag<["-"], "Wwrite-strings">, Group, Flags<[CC1Option, HelpHidden]>; def Wno_write_strings : Flag<["-"], "Wno-write-strings">, Group, Flags<[CC1Option, HelpHidden]>; -def W_Joined : Joined<["-"], "W">, Group, Flags<[CC1Option, CoreOption]>, +def W_Joined : Joined<["-"], "W">, Group, Flags<[CC1Option, CoreOption, FC1Option, FlangOption]>, MetaVarName<"">, HelpText<"Enable the specified warning">; def Xanalyzer : Separate<["-"], "Xanalyzer">, HelpText<"Pass to the static analyzer">, MetaVarName<"">, 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_W_Joined}); } 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_W_Joined)) { + 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/Driver/driver-help-hidden.f90 =================================================================== --- flang/test/Driver/driver-help-hidden.f90 +++ flang/test/Driver/driver-help-hidden.f90 @@ -47,6 +47,7 @@ ! CHECK-NEXT: -o Write output to ! CHECK-NEXT: -U Undefine macro ! CHECK-NEXT: --version Print version information +! CHECK-NEXT: -W Enable the specified warning ! CHECK-NEXT: -Xflang Pass to the flang compiler !------------------------------------------------------------- Index: flang/test/Driver/driver-help.f90 =================================================================== --- flang/test/Driver/driver-help.f90 +++ flang/test/Driver/driver-help.f90 @@ -47,6 +47,7 @@ ! HELP-NEXT: -o Write output to ! HELP-NEXT: -U Undefine macro ! HELP-NEXT: --version Print version information +! HELP-NEXT: -W Enable the specified warning ! HELP-NEXT: -Xflang Pass to the flang compiler !------------------------------------------------------------- @@ -94,6 +95,7 @@ ! HELP-FC1-NEXT: -test-io Run the InputOuputTest action. Use for development and testing only. ! HELP-FC1-NEXT: -U Undefine macro ! HELP-FC1-NEXT: --version Print version information +! HELP-FC1-NEXT: -W Enable the specified warning !--------------- ! EXPECTED ERROR 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