[PATCH] D126796: [clang][driver] adds `-print-diagnostics`

Christopher Di Bella via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 2 15:02:37 PDT 2022


cjdb updated this revision to Diff 433901.
cjdb added a comment.

- simplifies code
- minimises test to only a handful of cases


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126796/new/

https://reviews.llvm.org/D126796

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/DiagnosticIDs.cpp
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/print-diagnostic-options.c


Index: clang/test/Driver/print-diagnostic-options.c
===================================================================
--- /dev/null
+++ clang/test/Driver/print-diagnostic-options.c
@@ -0,0 +1,13 @@
+// Test that -print-diagnostic-options prints all warning groups
+
+// RUN: %clang -print-diagnostic-options | FileCheck %s
+
+// CHECK:  -W
+// CHECK:  -Wno-
+// CHECK:  -W#pragma-messages
+// CHECK:  -Wno-#pragma-messages
+// CHECK:  -W#warnings
+// CHECK:  -Wabi
+// CHECK:  -Wno-abi
+// CHECK:  -Wall
+// CHECK:  -Wno-all
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2006,6 +2006,13 @@
     return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_diagnostic_options)) {
+    std::vector<std::string> Flags = DiagnosticIDs::getDiagnosticFlags();
+    for (std::size_t I = 0; I != Flags.size(); I += 2)
+      llvm::outs() << "  " << Flags[I] << "\n  " << Flags[I + 1] << "\n\n";
+    return false;
+  }
+
   // FIXME: The following handlers should use a callback mechanism, we don't
   // know what the client would like to do.
   if (Arg *A = C.getArgs().getLastArg(options::OPT_print_file_name_EQ)) {
Index: clang/lib/Basic/DiagnosticIDs.cpp
===================================================================
--- clang/lib/Basic/DiagnosticIDs.cpp
+++ clang/lib/Basic/DiagnosticIDs.cpp
@@ -653,7 +653,7 @@
 }
 
 std::vector<std::string> DiagnosticIDs::getDiagnosticFlags() {
-  std::vector<std::string> Res;
+  std::vector<std::string> Res{"-W", "-Wno-"};
   for (size_t I = 1; DiagGroupNames[I] != '\0';) {
     std::string Diag(DiagGroupNames + I + 1, DiagGroupNames[I]);
     I += DiagGroupNames[I] + 1;
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -826,7 +826,7 @@
   HelpText<"Pass <arg> to the linker">, MetaVarName<"<arg>">,
   Group<Link_Group>;
 def Xoffload_linker : JoinedAndSeparate<["-"], "Xoffload-linker">,
-  HelpText<"Pass <arg> to the offload linkers or the ones idenfied by -<triple>">, 
+  HelpText<"Pass <arg> to the offload linkers or the ones idenfied by -<triple>">,
   MetaVarName<"<triple> <arg>">, Group<Link_Group>;
 def Xpreprocessor : Separate<["-"], "Xpreprocessor">, Group<Preprocessor_Group>,
   HelpText<"Pass <arg> to the preprocessor">, MetaVarName<"<arg>">;
@@ -3996,6 +3996,8 @@
   HelpText<"Print the paths used for finding ROCm installation">;
 def print_runtime_dir : Flag<["-", "--"], "print-runtime-dir">,
   HelpText<"Print the directory pathname containing clangs runtime libraries">;
+def print_diagnostic_options : Flag<["-", "--"], "print-diagnostic-options">,
+  HelpText<"Print all of Clang's warning options">;
 def private__bundle : Flag<["-"], "private_bundle">;
 def pthreads : Flag<["-"], "pthreads">;
 defm pthread : BoolOption<"", "pthread",


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126796.433901.patch
Type: text/x-patch
Size: 2996 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220602/70b69638/attachment.bin>


More information about the cfe-commits mailing list