20
20
#include " flang/Support/Version.h"
21
21
#include " flang/Tools/TargetSetup.h"
22
22
#include " flang/Version.inc"
23
- #include " clang/Basic/AllDiagnostics.h"
24
23
#include " clang/Basic/DiagnosticDriver.h"
25
24
#include " clang/Basic/DiagnosticOptions.h"
26
25
#include " clang/Driver/CommonArgs.h"
27
26
#include " clang/Driver/Driver.h"
28
- #include " clang/Driver/DriverDiagnostic.h"
29
27
#include " clang/Driver/OptionUtils.h"
30
28
#include " clang/Driver/Options.h"
31
29
#include " llvm/ADT/StringRef.h"
36
34
#include " llvm/Option/OptTable.h"
37
35
#include " llvm/Support/CodeGen.h"
38
36
#include " llvm/Support/FileSystem.h"
39
- #include " llvm/Support/FileUtilities.h"
40
37
#include " llvm/Support/Path.h"
41
38
#include " llvm/Support/Process.h"
42
39
#include " llvm/Support/raw_ostream.h"
@@ -975,10 +972,23 @@ static bool parseSemaArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
975
972
976
973
// / Parses all diagnostics related arguments and populates the variables
977
974
// / options accordingly. Returns false if new errors are generated.
975
+ // / FC1 driver entry point for parsing diagnostic arguments.
978
976
static bool parseDiagArgs (CompilerInvocation &res, llvm::opt::ArgList &args,
979
977
clang::DiagnosticsEngine &diags) {
980
978
unsigned numErrorsBefore = diags.getNumErrors ();
981
979
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
+
982
992
// -Werror option
983
993
// TODO: Currently throws a Diagnostic for anything other than -W<error>,
984
994
// this has to change when other -W<opt>'s are supported.
@@ -988,22 +998,26 @@ static bool parseDiagArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
988
998
for (const auto &wArg : wArgs) {
989
999
if (wArg == " error" ) {
990
1000
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 ;
996
1006
}
997
1007
}
998
1008
}
999
1009
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
+ }
1006
1015
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;
1007
1021
return diags.getNumErrors () == numErrorsBefore;
1008
1022
}
1009
1023
@@ -1078,16 +1092,6 @@ static bool parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
1078
1092
Fortran::common::LanguageFeature::OpenACC);
1079
1093
}
1080
1094
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
-
1091
1095
// -std=f2018
1092
1096
// TODO: Set proper options when more fortran standards
1093
1097
// are supported.
@@ -1096,6 +1100,7 @@ static bool parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
1096
1100
// We only allow f2018 as the given standard
1097
1101
if (standard == " f2018" ) {
1098
1102
res.setEnableConformanceChecks ();
1103
+ res.getFrontendOpts ().features .WarnOnAllNonstandard ();
1099
1104
} else {
1100
1105
const unsigned diagID =
1101
1106
diags.getCustomDiagID (clang::DiagnosticsEngine::Error,
@@ -1702,16 +1707,7 @@ void CompilerInvocation::setFortranOpts() {
1702
1707
if (frontendOptions.needProvenanceRangeToCharBlockMappings )
1703
1708
fortranOptions.needProvenanceRangeToCharBlockMappings = true ;
1704
1709
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 ;
1715
1711
}
1716
1712
1717
1713
std::unique_ptr<Fortran::semantics::SemanticsContext>
0 commit comments