[flang-commits] [clang] [flang] [flang][Driver] Support --no-warnings option (PR #107455)

Tarun Prabhu via flang-commits flang-commits at lists.llvm.org
Thu Sep 5 12:43:59 PDT 2024


https://github.com/tarunprabhu created https://github.com/llvm/llvm-project/pull/107455

Because of the way visibility is implemented in Options.td, options that are aliases do not inherit the visibility of the option being aliased. Therefore, explicitly set the visibility of the alias to be the same as the aliased option.

This partially addresses https://github.com/llvm/llvm-project/issues/89888

>From 90fcfe2139a08677bfd1e4d735d079bcc2d6db42 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu <tarun.prabhu at gmail.com>
Date: Thu, 5 Sep 2024 08:47:15 -0600
Subject: [PATCH 1/2] Throwaway commit prior to context switch

---
 clang/lib/Driver/ToolChains/Flang.cpp     | 1 +
 flang/lib/Frontend/CompilerInvocation.cpp | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 6ce79d27e98c48..fc6762f6bdae40 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -777,6 +777,7 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
   // Disable all warnings
   // TODO: Handle interactions between -w, -pedantic, -Wall, -WOption
   Args.AddLastArg(CmdArgs, options::OPT_w);
+  Args.AddLastArg(CmdArgs, options::OPT__no_warnings);
 
   // Forward flags for OpenMP. We don't do this if the current action is an
   // device offloading action other than OpenMP.
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 1d73397d330178..9b35d54f61a0d0 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -942,7 +942,8 @@ static bool parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
   }
 
   // -w
-  if (args.hasArg(clang::driver::options::OPT_w))
+  if (args.hasArg(clang::driver::options::OPT_w,
+                  clang::driver::options::OPT__no_warnings))
     res.setDisableWarnings();
 
   // -std=f2018

>From 3e0f2ce417ea8193384031caa3ba17fa654293f0 Mon Sep 17 00:00:00 2001
From: Tarun Prabhu <tarun.prabhu at gmail.com>
Date: Thu, 5 Sep 2024 13:34:51 -0600
Subject: [PATCH 2/2] [flang][Driver] Support --no-warnings option

Because of the way visibility is implemented in Options.td, options that are
aliases do not inherit the visibility of the option being aliased. For now,
explicitly set the visibility of the alias to be the same as the aliased option.

This partially addresses https://github.com/llvm/llvm-project/issues/89888
---
 clang/include/clang/Driver/Options.td | 4 +++-
 flang/test/Driver/w-option.f90        | 3 +++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 1b9b3f2c6600a3..049c6cf4cef955 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5978,7 +5978,9 @@ def _no_line_commands : Flag<["--"], "no-line-commands">, Alias<P>;
 def _no_standard_includes : Flag<["--"], "no-standard-includes">, Alias<nostdinc>;
 def _no_standard_libraries : Flag<["--"], "no-standard-libraries">, Alias<nostdlib>;
 def _no_undefined : Flag<["--"], "no-undefined">, Flags<[LinkerInput]>;
-def _no_warnings : Flag<["--"], "no-warnings">, Alias<w>;
+def _no_warnings : Flag<["--"], "no-warnings">,
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
+  Alias<w>;
 def _optimize_EQ : Joined<["--"], "optimize=">, Alias<O>;
 def _optimize : Flag<["--"], "optimize">, Alias<O>;
 def _output_class_directory_EQ : Joined<["--"], "output-class-directory=">, Alias<foutput_class_dir_EQ>;
diff --git a/flang/test/Driver/w-option.f90 b/flang/test/Driver/w-option.f90
index e34cddaab373a1..b6aa44a06ab729 100644
--- a/flang/test/Driver/w-option.f90
+++ b/flang/test/Driver/w-option.f90
@@ -4,6 +4,9 @@
 ! 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 the warnings are not generated with `--no-warnings` option.
+! RUN: %flang -c --no-warnings %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
 



More information about the flang-commits mailing list