2020#include " flang/Support/Version.h"
2121#include " flang/Tools/TargetSetup.h"
2222#include " flang/Version.inc"
23- #include " clang/Basic/AllDiagnostics.h"
2423#include " clang/Basic/DiagnosticDriver.h"
2524#include " clang/Basic/DiagnosticOptions.h"
2625#include " clang/Driver/CommonArgs.h"
2726#include " clang/Driver/Driver.h"
28- #include " clang/Driver/DriverDiagnostic.h"
2927#include " clang/Driver/OptionUtils.h"
3028#include " clang/Driver/Options.h"
3129#include " llvm/ADT/StringRef.h"
3634#include " llvm/Option/OptTable.h"
3735#include " llvm/Support/CodeGen.h"
3836#include " llvm/Support/FileSystem.h"
39- #include " llvm/Support/FileUtilities.h"
4037#include " llvm/Support/Path.h"
4138#include " llvm/Support/Process.h"
4239#include " llvm/Support/raw_ostream.h"
@@ -975,10 +972,23 @@ static bool parseSemaArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
975972
976973// / Parses all diagnostics related arguments and populates the variables
977974// / options accordingly. Returns false if new errors are generated.
975+ // / FC1 driver entry point for parsing diagnostic arguments.
978976static bool parseDiagArgs (CompilerInvocation &res, llvm::opt::ArgList &args,
979977 clang::DiagnosticsEngine &diags) {
980978 unsigned numErrorsBefore = diags.getNumErrors ();
981979
980+ auto &features{res.getFrontendOpts ().features };
981+ // The order of these flags (-pedantic -W<feature> -w) is important and is
982+ // chosen to match clang's behavior.
983+
984+ // -pedantic
985+ if (args.hasArg (clang::driver::options::OPT_pedantic)) {
986+ features.WarnOnAllNonstandard ();
987+ features.WarnOnAllUsage ();
988+ res.setEnableConformanceChecks ();
989+ res.setEnableUsageChecks ();
990+ }
991+
982992 // -Werror option
983993 // TODO: Currently throws a Diagnostic for anything other than -W<error>,
984994 // this has to change when other -W<opt>'s are supported.
@@ -988,22 +998,26 @@ static bool parseDiagArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
988998 for (const auto &wArg : wArgs) {
989999 if (wArg == " error" ) {
9901000 res.setWarnAsErr (true );
991- } else {
992- const unsigned diagID =
993- diags.getCustomDiagID (clang::DiagnosticsEngine::Error,
994- " Only `-Werror` is supported currently. " );
995- diags.Report (diagID);
1001+ // -W(no-)<feature>
1002+ } else if (!features. ApplyCliOption (wArg)) {
1003+ const unsigned diagID = diags.getCustomDiagID (
1004+ clang::DiagnosticsEngine::Error, " Unknown diagnostic option: -W%0 " );
1005+ diags.Report (diagID) << wArg ;
9961006 }
9971007 }
9981008 }
9991009
1000- // Default to off for `flang -fc1`.
1001- res.getFrontendOpts ().showColors =
1002- parseShowColorsArgs (args, /* defaultDiagColor=*/ false );
1003-
1004- // Honor color diagnostics.
1005- res.getDiagnosticOpts ().ShowColors = res.getFrontendOpts ().showColors ;
1010+ // -w
1011+ if (args.hasArg (clang::driver::options::OPT_w)) {
1012+ features.DisableAllWarnings ();
1013+ res.setDisableWarnings ();
1014+ }
10061015
1016+ // Default to off for `flang -fc1`.
1017+ bool showColors{parseShowColorsArgs (args, false )};
1018+ diags.getDiagnosticOptions ().ShowColors = showColors;
1019+ res.getDiagnosticOpts ().ShowColors = showColors;
1020+ res.getFrontendOpts ().showColors = showColors;
10071021 return diags.getNumErrors () == numErrorsBefore;
10081022}
10091023
@@ -1078,16 +1092,6 @@ static bool parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
10781092 Fortran::common::LanguageFeature::OpenACC);
10791093 }
10801094
1081- // -pedantic
1082- if (args.hasArg (clang::driver::options::OPT_pedantic)) {
1083- res.setEnableConformanceChecks ();
1084- res.setEnableUsageChecks ();
1085- }
1086-
1087- // -w
1088- if (args.hasArg (clang::driver::options::OPT_w))
1089- res.setDisableWarnings ();
1090-
10911095 // -std=f2018
10921096 // TODO: Set proper options when more fortran standards
10931097 // are supported.
@@ -1096,6 +1100,7 @@ static bool parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
10961100 // We only allow f2018 as the given standard
10971101 if (standard == " f2018" ) {
10981102 res.setEnableConformanceChecks ();
1103+ res.getFrontendOpts ().features .WarnOnAllNonstandard ();
10991104 } else {
11001105 const unsigned diagID =
11011106 diags.getCustomDiagID (clang::DiagnosticsEngine::Error,
@@ -1702,16 +1707,7 @@ void CompilerInvocation::setFortranOpts() {
17021707 if (frontendOptions.needProvenanceRangeToCharBlockMappings )
17031708 fortranOptions.needProvenanceRangeToCharBlockMappings = true ;
17041709
1705- if (getEnableConformanceChecks ())
1706- fortranOptions.features .WarnOnAllNonstandard ();
1707-
1708- if (getEnableUsageChecks ())
1709- fortranOptions.features .WarnOnAllUsage ();
1710-
1711- if (getDisableWarnings ()) {
1712- fortranOptions.features .DisableAllNonstandardWarnings ();
1713- fortranOptions.features .DisableAllUsageWarnings ();
1714- }
1710+ fortranOptions.features = frontendOptions.features ;
17151711}
17161712
17171713std::unique_ptr<Fortran::semantics::SemanticsContext>
0 commit comments