analyzer: fix warning_event::get_desc for global state changes
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 17 Sep 2020 13:41:29 +0000 (09:41 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Fri, 18 Sep 2020 21:39:46 +0000 (17:39 -0400)
When experimenting the a new state_machine with global state I noticed
that the fallback handling in warning_event::get_desc assumes we have
per-value states, and ICEs on global states.  Fixed thusly.

gcc/analyzer/ChangeLog:
* checker-path.cc (warning_event::get_desc): Handle global state
changes.

gcc/analyzer/checker-path.cc

index 2503d024a830fd353c1bb4a8aacd4ef8542b8cba..c28131651c66000acfa1cf1ced848d18bb603a0e 100644 (file)
@@ -872,11 +872,17 @@ warning_event::get_desc (bool can_colorize) const
        {
          if (m_sm && flag_analyzer_verbose_state_changes)
            {
-             label_text result
-               = make_label_text (can_colorize,
-                                  "%s (%qE is in state %qs)",
-                                  ev_desc.m_buffer,
-                                  m_var, m_state->get_name ());
+             label_text result;
+             if (m_var)
+               result = make_label_text (can_colorize,
+                                         "%s (%qE is in state %qs)",
+                                         ev_desc.m_buffer,
+                                         m_var, m_state->get_name ());
+             else
+               result = make_label_text (can_colorize,
+                                         "%s (in global state %qs)",
+                                         ev_desc.m_buffer,
+                                         m_state->get_name ());
              ev_desc.maybe_free ();
              return result;
            }
@@ -886,9 +892,16 @@ warning_event::get_desc (bool can_colorize) const
     }
 
   if (m_sm)
-    return make_label_text (can_colorize,
-                           "here (%qE is in state %qs)",
-                           m_var, m_state->get_name ());
+    {
+      if (m_var)
+       return make_label_text (can_colorize,
+                               "here (%qE is in state %qs)",
+                               m_var, m_state->get_name ());
+      else
+       return make_label_text (can_colorize,
+                               "here (in global state %qs)",
+                               m_state->get_name ());
+    }
   else
     return label_text::borrow ("here");
 }