[flang-commits] [flang] 602df27 - [Flang] RFC: Add support for -w option 1/n (#90420)
via flang-commits
flang-commits at lists.llvm.org
Wed May 8 02:00:53 PDT 2024
Author: Kiran Chandramohan
Date: 2024-05-08T10:00:48+01:00
New Revision: 602df270a9bfcb52980a93c85eb615c0d91eba0c
URL: https://github.com/llvm/llvm-project/commit/602df270a9bfcb52980a93c85eb615c0d91eba0c
DIFF: https://github.com/llvm/llvm-project/commit/602df270a9bfcb52980a93c85eb615c0d91eba0c.diff
LOG: [Flang] RFC: Add support for -w option 1/n (#90420)
Add support for the -w option to switch OFF all Flang
warnings. This patch only supports switching OFF the
frontend warnings.
TODO : Support for MLIR, LLVM and Driver warnings.
TODO : Support interactions between -w, -pedantic, -Wall
Added:
flang/test/Driver/w-option.f90
Modified:
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/include/flang/Frontend/CompilerInvocation.h
flang/lib/Frontend/CompilerInvocation.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 2c319ba38a298..734ae7833f5c3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5703,7 +5703,7 @@ def whatsloaded : Flag<["-"], "whatsloaded">;
def why_load : Flag<["-"], "why_load">;
def whyload : Flag<["-"], "whyload">, Alias<why_load>;
def w : Flag<["-"], "w">, HelpText<"Suppress all warnings">,
- Visibility<[ClangOption, CC1Option]>,
+ Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
MarshallingInfoFlag<DiagnosticOpts<"IgnoreWarnings">>;
def x : JoinedOrSeparate<["-"], "x">,
Flags<[NoXarchOption]>,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 8955b9fb653c2..436a9c418a5f9 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -748,6 +748,10 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
// Add other compile options
addOtherOptions(Args, CmdArgs);
+ // Disable all warnings
+ // TODO: Handle interactions between -w, -pedantic, -Wall, -WOption
+ Args.AddLastArg(CmdArgs, options::OPT_w);
+
// Forward flags for OpenMP. We don't do this if the current action is an
// device offloading action other than OpenMP.
if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
diff --git a/flang/include/flang/Frontend/CompilerInvocation.h b/flang/include/flang/Frontend/CompilerInvocation.h
index 4924d090eaf9c..0fefaecfe4f06 100644
--- a/flang/include/flang/Frontend/CompilerInvocation.h
+++ b/flang/include/flang/Frontend/CompilerInvocation.h
@@ -114,8 +114,10 @@ class CompilerInvocation : public CompilerInvocationBase {
// Fortran Dialect options
Fortran::common::IntrinsicTypeDefaultKinds defaultKinds;
+ // Fortran Warning options
bool enableConformanceChecks = false;
bool enableUsageChecks = false;
+ bool disableWarnings = false;
/// Used in e.g. unparsing to dump the analyzed rather than the original
/// parse-tree objects.
@@ -197,6 +199,9 @@ class CompilerInvocation : public CompilerInvocationBase {
bool &getEnableUsageChecks() { return enableUsageChecks; }
const bool &getEnableUsageChecks() const { return enableUsageChecks; }
+ bool &getDisableWarnings() { return disableWarnings; }
+ const bool &getDisableWarnings() const { return disableWarnings; }
+
Fortran::parser::AnalyzedObjectsAsFortran &getAsFortran() {
return asFortran;
}
@@ -226,6 +231,9 @@ class CompilerInvocation : public CompilerInvocationBase {
// Enables the usage checks
void setEnableUsageChecks() { enableUsageChecks = true; }
+ // Disables all Warnings
+ void setDisableWarnings() { disableWarnings = true; }
+
/// Useful setters
void setArgv0(const char *dir) { argv0 = dir; }
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index f1b7b53975398..4318286e74152 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -975,6 +975,11 @@ static bool parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
res.setEnableConformanceChecks();
res.setEnableUsageChecks();
}
+
+ // -w
+ if (args.hasArg(clang::driver::options::OPT_w))
+ res.setDisableWarnings();
+
// -std=f2018
// TODO: Set proper options when more fortran standards
// are supported.
@@ -1403,6 +1408,11 @@ void CompilerInvocation::setFortranOpts() {
if (getEnableUsageChecks())
fortranOptions.features.WarnOnAllUsage();
+
+ if (getDisableWarnings()) {
+ fortranOptions.features.DisableAllNonstandardWarnings();
+ fortranOptions.features.DisableAllUsageWarnings();
+ }
}
std::unique_ptr<Fortran::semantics::SemanticsContext>
diff --git a/flang/test/Driver/w-option.f90 b/flang/test/Driver/w-option.f90
new file mode 100644
index 0000000000000..e34cddaab373a
--- /dev/null
+++ b/flang/test/Driver/w-option.f90
@@ -0,0 +1,31 @@
+! Test the default setting. Emit warnings only.
+! RUN: %flang -c %s 2>&1 | FileCheck %s -check-prefix=DEFAULT
+
+! Test that the warnings are not generated with `-w` option.
+! RUN: %flang -c -w %s 2>&1 | FileCheck --allow-empty %s -check-prefix=WARNING
+
+! Test that warnings are portability messages are generated.
+! RUN: %flang -c -pedantic %s 2>&1 | FileCheck %s -check-prefixes=DEFAULT,PORTABILITY
+
+! Test that warnings and portability messages are not generated.
+! TODO: Support the last flag wins behaviour.
+! RUN: %flang -c -pedantic -w %s 2>&1 | FileCheck --allow-empty %s -check-prefixes=WARNING,PORTABILITY-WARNING
+! RUN: %flang -c -w -pedantic %s 2>&1 | FileCheck --allow-empty %s -check-prefixes=WARNING,PORTABILITY-WARNING
+! DEFAULT: warning: Label '40' is in a construct that should not be used as a branch target here
+! DEFAULT: warning: Label '50' is in a construct that should not be used as a branch target here
+! WARNING-NOT: warning
+! PORTABILITY: portability: Statement function 'sf1' should not contain an array constructor
+! PORTABILITY-WARNING-NOT: portability
+
+subroutine sub01(n)
+ integer n
+ GOTO (40,50,60) n
+ if (n .eq. 1) then
+40 print *, "xyz"
+50 end if
+60 continue
+end subroutine sub01
+
+subroutine sub02
+ sf1(n) = sum([(j,j=1,n)])
+end subroutine sub02
More information about the flang-commits
mailing list