https://github.com/kiranchandramohan updated 
https://github.com/llvm/llvm-project/pull/90420

>From 78e91d2d84638ded51267c5e0720cc1d1d4d773b Mon Sep 17 00:00:00 2001
From: Kiran Chandramohan <kiran.chandramo...@arm.com>
Date: Fri, 26 Apr 2024 09:26:11 +0000
Subject: [PATCH 1/2] [Flang][Driver] Add support for -w option 1/n

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
---
 clang/include/clang/Driver/Options.td         |  2 +-
 clang/lib/Driver/ToolChains/Flang.cpp         |  4 ++++
 .../flang/Frontend/CompilerInvocation.h       |  8 +++++++
 flang/lib/Frontend/CompilerInvocation.cpp     | 10 ++++++++
 flang/test/Driver/w-option.f90                | 23 +++++++++++++++++++
 5 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Driver/w-option.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2c319ba38a2985..734ae7833f5c35 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 8955b9fb653c2a..436a9c418a5f93 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 4924d090eaf9c0..0fefaecfe4f06f 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 f1b7b53975398e..4318286e74152e 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 00000000000000..d1524059cace6f
--- /dev/null
+++ b/flang/test/Driver/w-option.f90
@@ -0,0 +1,23 @@
+! RUN: %flang -c %s 2>&1 | FileCheck %s
+! RUN: %flang -c -w %s 2>&1 | FileCheck --allow-empty %s -check-prefix=CHECK-W
+! RUN: %flang -c -pedantic %s 2>&1 | FileCheck %s 
-check-prefixes=CHECK,CHECK-PORT
+! RUN: %flang -c -pedantic -w %s 2>&1 | FileCheck --allow-empty %s 
-check-prefixes=CHECK-W,CHECK-PORT-W
+! RUN: %flang -c -w -pedantic %s 2>&1 | FileCheck  --allow-empty %s 
-check-prefixes=CHECK-W,CHECK-PORT-W
+! CHECK: warning: Label '40' is in a construct that should not be used as a 
branch target here
+! CHECK: warning: Label '50' is in a construct that should not be used as a 
branch target here
+! CHECK-W-NOT: warning
+! CHECK-PORT: portability: Statement function 'sf1' should not contain an 
array constructor
+! CHECK-PORT-W-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

>From facbbc32905a1b81776187397e1f5ab378b66134 Mon Sep 17 00:00:00 2001
From: Kiran Chandramohan <kiran.chandramo...@arm.com>
Date: Tue, 7 May 2024 19:44:47 +0000
Subject: [PATCH 2/2] Address review comments and rebase

---
 flang/test/Driver/w-option.f90 | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/flang/test/Driver/w-option.f90 b/flang/test/Driver/w-option.f90
index d1524059cace6f..e34cddaab373a1 100644
--- a/flang/test/Driver/w-option.f90
+++ b/flang/test/Driver/w-option.f90
@@ -1,13 +1,21 @@
-! RUN: %flang -c %s 2>&1 | FileCheck %s
-! RUN: %flang -c -w %s 2>&1 | FileCheck --allow-empty %s -check-prefix=CHECK-W
-! RUN: %flang -c -pedantic %s 2>&1 | FileCheck %s 
-check-prefixes=CHECK,CHECK-PORT
-! RUN: %flang -c -pedantic -w %s 2>&1 | FileCheck --allow-empty %s 
-check-prefixes=CHECK-W,CHECK-PORT-W
-! RUN: %flang -c -w -pedantic %s 2>&1 | FileCheck  --allow-empty %s 
-check-prefixes=CHECK-W,CHECK-PORT-W
-! CHECK: warning: Label '40' is in a construct that should not be used as a 
branch target here
-! CHECK: warning: Label '50' is in a construct that should not be used as a 
branch target here
-! CHECK-W-NOT: warning
-! CHECK-PORT: portability: Statement function 'sf1' should not contain an 
array constructor
-! CHECK-PORT-W-NOT: portability
+! 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

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to