[clang] 288c1bf - [clang][driver] adds `-print-diagnostics`

Christopher Di Bella via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 8 10:55:57 PDT 2022


Author: Christopher Di Bella
Date: 2022-06-08T17:55:31Z
New Revision: 288c1bff96fc9042d01b7055dc6e1049d8b54b26

URL: https://github.com/llvm/llvm-project/commit/288c1bff96fc9042d01b7055dc6e1049d8b54b26
DIFF: https://github.com/llvm/llvm-project/commit/288c1bff96fc9042d01b7055dc6e1049d8b54b26.diff

LOG: [clang][driver] adds `-print-diagnostics`

Prints a list of all the warnings that Clang offers.

Differential Revision: https://reviews.llvm.org/D126796

Added: 
    clang/test/Driver/print-diagnostic-options.c

Modified: 
    clang/include/clang/Driver/Options.td
    clang/lib/Basic/DiagnosticIDs.cpp
    clang/lib/Driver/Driver.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index b2feed0e36329..de3cd2ded8bef 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4005,6 +4005,8 @@ def print_rocm_search_dirs : Flag<["-", "--"], "print-rocm-search-dirs">,
   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",

diff  --git a/clang/lib/Basic/DiagnosticIDs.cpp b/clang/lib/Basic/DiagnosticIDs.cpp
index a8a17994f7fc8..cc6b19646d1d6 100644
--- a/clang/lib/Basic/DiagnosticIDs.cpp
+++ b/clang/lib/Basic/DiagnosticIDs.cpp
@@ -653,7 +653,7 @@ StringRef DiagnosticIDs::getWarningOptionForDiag(unsigned DiagID) {
 }
 
 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;

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 8e698a2a7cbef..8f7e411696e2c 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2010,6 +2010,13 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
     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)) {

diff  --git a/clang/test/Driver/print-diagnostic-options.c b/clang/test/Driver/print-diagnostic-options.c
new file mode 100644
index 0000000000000..fc6d1bf2eff53
--- /dev/null
+++ b/clang/test/Driver/print-diagnostic-options.c
@@ -0,0 +1,13 @@
+// Test that -print-diagnostic-options prints warning groups and disablers
+
+// 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


        


More information about the cfe-commits mailing list