]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
diagnostics: convert diagnostic_event::meaning enums to enum class
authorDavid Malcolm <dmalcolm@redhat.com>
Mon, 30 Jun 2025 19:05:07 +0000 (15:05 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Mon, 30 Jun 2025 19:05:07 +0000 (15:05 -0400)
Modernization; no functional change intended.

gcc/analyzer/ChangeLog:
* checker-event.cc (function_entry_event::get_meaning): Convert
diagnostic_event::meaning enums to enum class.
(cfg_edge_event::get_meaning): Likewise.
(call_event::get_meaning): Likewise.
(return_event::get_meaning): Likewise.
(start_consolidated_cfg_edges_event::get_meaning): Likewise.
(inlined_call_event::get_meaning): Likewise.
(warning_event::get_meaning): Likewise.
* sm-fd.cc (fd_diagnostic::get_meaning_for_state_change):
Likewise.
* sm-file.cc (file_diagnostic::get_meaning_for_state_change):
Likewise.
* sm-malloc.cc (malloc_diagnostic::get_meaning_for_state_change):
Likewise.
* sm-sensitive.cc
(exposure_through_output_file::get_meaning_for_state_change):
Likewise.
* sm-taint.cc (taint_diagnostic::get_meaning_for_state_change):
Likewise.
* varargs.cc
(va_list_sm_diagnostic::get_meaning_for_state_change): Likewise.

gcc/ChangeLog:
* diagnostic-format-sarif.cc
(sarif_builder::maybe_make_kinds_array): Convert
diagnostic_event::meaning enums to enum class.
* diagnostic-path-output.cc (path_label::get_text): Likewise.
* diagnostic-path.cc
(diagnostic_event::meaning::maybe_get_verb_str): Likewise.
(diagnostic_event::meaning::maybe_get_noun_str): Likewise.
(diagnostic_event::meaning::maybe_get_property_str): Likewise.
* diagnostic-path.h (diagnostic_event::verb): Likewise.
(diagnostic_event::noun): Likewise.
(diagnostic_event::property): Likewise.
(diagnostic_event::meaning): Likewise.

gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_gil_plugin.cc
(gil_diagnostic::get_meaning_for_state_change): Convert
diagnostic_event::meaning enums to enum class.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
12 files changed:
gcc/analyzer/checker-event.cc
gcc/analyzer/sm-fd.cc
gcc/analyzer/sm-file.cc
gcc/analyzer/sm-malloc.cc
gcc/analyzer/sm-sensitive.cc
gcc/analyzer/sm-taint.cc
gcc/analyzer/varargs.cc
gcc/diagnostic-format-sarif.cc
gcc/diagnostic-path-output.cc
gcc/diagnostic-path.cc
gcc/diagnostic-path.h
gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.cc

index 04b66bf85d6354b27e96a81b71e6cdacf471ea21..767e962589e0cb43b5fc119bf2d32b96cd5e5739 100644 (file)
@@ -398,7 +398,7 @@ function_entry_event::print_desc (pretty_printer &pp) const
 diagnostic_event::meaning
 function_entry_event::get_meaning () const
 {
-  return meaning (VERB_enter, NOUN_function);
+  return meaning (verb::enter, noun::function);
 }
 
 /* class state_change_event : public checker_event.  */
@@ -632,9 +632,9 @@ cfg_edge_event::get_meaning () const
 {
   const cfg_superedge& cfg_sedge = get_cfg_superedge ();
   if (cfg_sedge.true_value_p ())
-    return meaning (VERB_branch, PROPERTY_true);
+    return meaning (verb::branch, property::true_);
   else if (cfg_sedge.false_value_p ())
-    return meaning (VERB_branch, PROPERTY_false);
+    return meaning (verb::branch, property::false_);
   else
     return meaning ();
 }
@@ -880,7 +880,7 @@ call_event::print_desc (pretty_printer &pp) const
 diagnostic_event::meaning
 call_event::get_meaning () const
 {
-  return meaning (VERB_call, NOUN_function);
+  return meaning (verb::call, noun::function);
 }
 
 /* Override of checker_event::is_call_p for calls.  */
@@ -964,7 +964,7 @@ return_event::print_desc (pretty_printer &pp) const
 diagnostic_event::meaning
 return_event::get_meaning () const
 {
-  return meaning (VERB_return, NOUN_function);
+  return meaning (verb::return_, noun::function);
 }
 
 /* Override of checker_event::is_return_p for returns.  */
@@ -991,8 +991,8 @@ start_consolidated_cfg_edges_event::print_desc (pretty_printer &pp) const
 diagnostic_event::meaning
 start_consolidated_cfg_edges_event::get_meaning () const
 {
-  return meaning (VERB_branch,
-                 (m_edge_sense ? PROPERTY_true : PROPERTY_false));
+  return meaning (verb::branch,
+                 (m_edge_sense ? property::true_ : property::false_));
 }
 
 /* class inlined_call_event : public checker_event.  */
@@ -1012,7 +1012,7 @@ inlined_call_event::print_desc (pretty_printer &pp) const
 diagnostic_event::meaning
 inlined_call_event::get_meaning () const
 {
-  return meaning (VERB_call, NOUN_function);
+  return meaning (verb::call, noun::function);
 }
 
 /* class setjmp_event : public checker_event.  */
@@ -1252,7 +1252,7 @@ warning_event::print_desc (pretty_printer &pp) const
 diagnostic_event::meaning
 warning_event::get_meaning () const
 {
-  return meaning (VERB_danger, NOUN_unknown);
+  return meaning (verb::danger, noun::unknown);
 }
 
 const program_state *
index 09c311594bab6bebefd6c8965773fb7fd73943be..3a9162fdb7d84cbfd3c81eaf7e1689283e08a8a9 100644 (file)
@@ -401,11 +401,11 @@ public:
            || change.m_new_state == m_sm.m_new_datagram_socket
            || change.m_new_state == m_sm.m_new_stream_socket
            || change.m_new_state == m_sm.m_new_unknown_socket))
-      return diagnostic_event::meaning (diagnostic_event::VERB_acquire,
-                        diagnostic_event::NOUN_resource);
+      return diagnostic_event::meaning (diagnostic_event::verb::acquire,
+                                       diagnostic_event::noun::resource);
     if (change.m_new_state == m_sm.m_closed)
-      return diagnostic_event::meaning (diagnostic_event::VERB_release,
-                        diagnostic_event::NOUN_resource);
+      return diagnostic_event::meaning (diagnostic_event::verb::release,
+                                       diagnostic_event::noun::resource);
     return diagnostic_event::meaning ();
   }
 
index 61e24248c0806313b5df77da4bca35fb7855344a..4b1fc77887634973adeea391df029178651d6bc3 100644 (file)
@@ -161,11 +161,11 @@ public:
   {
     if (change.m_old_state == m_sm.get_start_state ()
        && change.m_new_state == m_sm.m_unchecked)
-      return diagnostic_event::meaning (diagnostic_event::VERB_acquire,
-                                       diagnostic_event::NOUN_resource);
+      return diagnostic_event::meaning (diagnostic_event::verb::acquire,
+                                       diagnostic_event::noun::resource);
     if (change.m_new_state == m_sm.m_closed)
-      return diagnostic_event::meaning (diagnostic_event::VERB_release,
-                                       diagnostic_event::NOUN_resource);
+      return diagnostic_event::meaning (diagnostic_event::verb::release,
+                                       diagnostic_event::noun::resource);
     return diagnostic_event::meaning ();
   }
 
index b9563b9358878df9619a5cd7363b0edbdec6d39c..d39d5770834a32d37d201d1f50b6076cfccbe38a 100644 (file)
@@ -819,11 +819,11 @@ public:
   {
     if (change.m_old_state == m_sm.get_start_state ()
        && unchecked_p (change.m_new_state))
-      return diagnostic_event::meaning (diagnostic_event::VERB_acquire,
-                                       diagnostic_event::NOUN_memory);
+      return diagnostic_event::meaning (diagnostic_event::verb::acquire,
+                                       diagnostic_event::noun::memory);
     if (freed_p (change.m_new_state))
-      return diagnostic_event::meaning (diagnostic_event::VERB_release,
-                                       diagnostic_event::NOUN_memory);
+      return diagnostic_event::meaning (diagnostic_event::verb::release,
+                                       diagnostic_event::noun::memory);
     return diagnostic_event::meaning ();
   }
 
index 7bd5ef68103f4180d9f596bbaf5908c5298319d6..f8fcdede8d8ef062d1fd0850183059050f68df10 100644 (file)
@@ -111,8 +111,8 @@ public:
     const final override
   {
     if (change.m_new_state == m_sm.m_sensitive)
-      return diagnostic_event::meaning (diagnostic_event::VERB_acquire,
-                                       diagnostic_event::NOUN_sensitive);
+      return diagnostic_event::meaning (diagnostic_event::verb::acquire,
+                                       diagnostic_event::noun::sensitive);
     return diagnostic_event::meaning ();
   }
   bool
index e782081ac2d7f63e1095f1f102dc0a142c6d87d4..12b4e5d998012c0e23f15fd66a0551daa056e2e4 100644 (file)
@@ -214,8 +214,8 @@ public:
     const final override
   {
     if (change.m_new_state == m_sm.m_tainted)
-      return diagnostic_event::meaning (diagnostic_event::VERB_acquire,
-                                       diagnostic_event::NOUN_taint);
+      return diagnostic_event::meaning (diagnostic_event::verb::acquire,
+                                       diagnostic_event::noun::taint);
     return diagnostic_event::meaning ();
   }
 
index 3b8f86364be44c1fc110e95153f4a960cf6d023b..44d567ac16508f31551c6bc165db22ab6f4126be 100644 (file)
@@ -339,11 +339,11 @@ public:
     const final override
   {
     if (change.m_new_state == m_sm.m_started)
-      return diagnostic_event::meaning (diagnostic_event::VERB_acquire,
-                                       diagnostic_event::NOUN_resource);
+      return diagnostic_event::meaning (diagnostic_event::verb::acquire,
+                                       diagnostic_event::noun::resource);
     if (change.m_new_state == m_sm.m_ended)
-      return diagnostic_event::meaning (diagnostic_event::VERB_release,
-                                       diagnostic_event::NOUN_resource);
+      return diagnostic_event::meaning (diagnostic_event::verb::release,
+                                       diagnostic_event::noun::resource);
     return diagnostic_event::meaning ();
   }
 
index d4ebe5a31edcbe8d2e02dfb43773d6749194bae4..3fdc6134a1be9ebf243650a5a0e4c2fe0d067222 100644 (file)
@@ -3005,9 +3005,9 @@ populate_thread_flow_location_object (sarif_result &result,
 std::unique_ptr<json::array>
 sarif_builder::maybe_make_kinds_array (diagnostic_event::meaning m) const
 {
-  if (m.m_verb == diagnostic_event::VERB_unknown
-      && m.m_noun == diagnostic_event::NOUN_unknown
-      && m.m_property == diagnostic_event::PROPERTY_unknown)
+  if (m.m_verb == diagnostic_event::verb::unknown
+      && m.m_noun == diagnostic_event::noun::unknown
+      && m.m_property == diagnostic_event::property::unknown)
     return nullptr;
 
   auto kinds_arr = std::make_unique<json::array> ();
index 4bec3a66267f62dd001eb2d40ba6808441633bd5..f8a424675df17228f058210bba6171bccc70bd60 100644 (file)
@@ -114,7 +114,7 @@ class path_label : public range_label
     pp_printf (pp.get (), "%@", &event_id);
     pp_space (pp.get ());
 
-    if (meaning.m_verb == diagnostic_event::VERB_danger
+    if (meaning.m_verb == diagnostic_event::verb::danger
        && m_allow_emojis)
       {
        pp_unicode_character (pp.get (), 0x26A0); /* U+26A0 WARNING SIGN.  */
index 0c617edeaa5174fbccd0a49802466ee5f1e3b796..6af24ffea38035dc2f32e52ca6b3b861a596430c 100644 (file)
@@ -77,23 +77,23 @@ diagnostic_event::meaning::maybe_get_verb_str (enum verb v)
     {
     default:
       gcc_unreachable ();
-    case VERB_unknown:
-      return NULL;
-    case VERB_acquire:
+    case verb::unknown:
+      return nullptr;
+    case verb::acquire:
       return "acquire";
-    case VERB_release:
+    case verb::release:
       return "release";
-    case VERB_enter:
+    case verb::enter:
       return "enter";
-    case VERB_exit:
+    case verb::exit:
       return "exit";
-    case VERB_call:
+    case verb::call:
       return "call";
-    case VERB_return:
+    case verb::return_:
       return "return";
-    case VERB_branch:
+    case verb::branch:
       return "branch";
-    case VERB_danger:
+    case verb::danger:
       return "danger";
     }
 }
@@ -108,19 +108,19 @@ diagnostic_event::meaning::maybe_get_noun_str (enum noun n)
     {
     default:
       gcc_unreachable ();
-    case NOUN_unknown:
-      return NULL;
-    case NOUN_taint:
+    case noun::unknown:
+      return nullptr;
+    case noun::taint:
       return "taint";
-    case NOUN_sensitive:
+    case noun::sensitive:
       return "sensitive";
-    case NOUN_function:
+    case noun::function:
       return "function";
-    case NOUN_lock:
+    case noun::lock:
       return "lock";
-    case NOUN_memory:
+    case noun::memory:
       return "memory";
-    case NOUN_resource:
+    case noun::resource:
       return "resource";
     }
 }
@@ -135,11 +135,11 @@ diagnostic_event::meaning::maybe_get_property_str (enum property p)
     {
     default:
       gcc_unreachable ();
-    case PROPERTY_unknown:
-      return NULL;
-    case PROPERTY_true:
+    case property::unknown:
+      return nullptr;
+    case property::true_:
       return "true";
-    case PROPERTY_false:
+    case property::false_:
       return "false";
     }
 }
index a3987a015a3e2da254fe0349baa3493e170d1265..e68f7681a5eb2a433dc0f36e8b2d57466734f126 100644 (file)
@@ -75,59 +75,59 @@ class diagnostic_event
  public:
   /* Enums for giving a sense of what this event means.
      Roughly corresponds to SARIF v2.1.0 section 3.38.8.  */
-  enum verb
+  enum class verb
   {
-    VERB_unknown,
+    unknown,
 
-    VERB_acquire,
-    VERB_release,
-    VERB_enter,
-    VERB_exit,
-    VERB_call,
-    VERB_return,
-    VERB_branch,
+    acquire,
+    release,
+    enter,
+    exit,
+    call,
+    return_,
+    branch,
 
-    VERB_danger
+    danger
   };
-  enum noun
+  enum class noun
   {
-    NOUN_unknown,
-
-    NOUN_taint,
-    NOUN_sensitive, // this one isn't in SARIF v2.1.0; filed as https://github.com/oasis-tcs/sarif-spec/issues/530
-    NOUN_function,
-    NOUN_lock,
-    NOUN_memory,
-    NOUN_resource
+    unknown,
+
+    taint,
+    sensitive, // this one isn't in SARIF v2.1.0; filed as https://github.com/oasis-tcs/sarif-spec/issues/530
+    function,
+    lock,
+    memory,
+    resource
   };
-  enum property
+  enum class property
   {
-    PROPERTY_unknown,
+    unknown,
 
-    PROPERTY_true,
-    PROPERTY_false
+    true_,
+    false_
   };
   /* A bundle of such enums, allowing for descriptions of the meaning of
      an event, such as
-     - "acquire memory": meaning (VERB_acquire, NOUN_memory)
-     - "take true branch"": meaning (VERB_branch, PROPERTY_true)
-     - "return from function": meaning (VERB_return, NOUN_function)
+     - "acquire memory": meaning (verb::acquire, noun::memory)
+     - "take true branch"": meaning (verb::branch, property::true)
+     - "return from function": meaning (verb::return, noun::function)
      etc, as per SARIF's threadFlowLocation "kinds" property
      (SARIF v2.1.0 section 3.38.8).  */
   struct meaning
   {
     meaning ()
-    : m_verb (VERB_unknown),
-      m_noun (NOUN_unknown),
-      m_property (PROPERTY_unknown)
+    : m_verb (verb::unknown),
+      m_noun (noun::unknown),
+      m_property (property::unknown)
     {
     }
     meaning (enum verb verb, enum noun noun)
-    : m_verb (verb), m_noun (noun), m_property (PROPERTY_unknown)
+    : m_verb (verb), m_noun (noun), m_property (property::unknown)
     {
     }
     meaning (enum verb verb, enum property property)
-    : m_verb (verb), m_noun (NOUN_unknown), m_property (property)
+    : m_verb (verb), m_noun (noun::unknown), m_property (property)
     {
     }
 
index 6f4cbc23c7b39dab4e024f5543f6f5c8be1ce0b5..fa2f2fa016104b79508d9b3b5cce70098536cb93 100644 (file)
@@ -127,11 +127,11 @@ public:
     if (change.is_global_p ())
       {
        if (change.m_new_state == m_sm.m_released_gil)
-         return diagnostic_event::meaning (diagnostic_event::VERB_release,
-                                           diagnostic_event::NOUN_lock);
+         return diagnostic_event::meaning (diagnostic_event::verb::release,
+                                           diagnostic_event::noun::lock);
        else if (change.m_new_state == m_sm.get_start_state ())
-         return diagnostic_event::meaning (diagnostic_event::VERB_acquire,
-                                           diagnostic_event::NOUN_lock);
+         return diagnostic_event::meaning (diagnostic_event::verb::acquire,
+                                           diagnostic_event::noun::lock);
       }
     return diagnostic_event::meaning ();
   }