[PATCH] analyzer: add get_meaning_for_state_change vfunc to fd_diagnostic in sm-fd.cc [PR106286]

Immad Mir mirimmad@outlook.com
Sat Jul 23 16:38:29 GMT 2022


This patch adds get_meaning_for_state_change vfunc to
fd_diagnostic in sm-fd.cc which could be used by SARIF output.

Lightly tested in x86_64 Linux.

gcc/analyzer/ChangeLog:
	PR analyzer/106286
	* sm-fd.cc:
	(fd_diagnostic::get_meaning_for_state_change): New.

Signed-off-by: Immad Mir <mirimmad@outlook.com>
---
 gcc/analyzer/sm-fd.cc | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/gcc/analyzer/sm-fd.cc b/gcc/analyzer/sm-fd.cc
index c3dac48509e..f77b1f4d3e2 100644
--- a/gcc/analyzer/sm-fd.cc
+++ b/gcc/analyzer/sm-fd.cc
@@ -229,6 +229,22 @@ public:
     return label_text ();
   }
 
+  diagnostic_event::meaning
+  get_meaning_for_state_change (
+      const evdesc::state_change &change) const final override
+  {
+    if (change.m_old_state == m_sm.get_start_state ()
+            && (change.m_new_state == m_sm.m_unchecked_read_write
+        || change.m_new_state == m_sm.m_unchecked_read_only
+        || change.m_new_state == m_sm.m_unchecked_write_only))
+      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 ();
+  }
+
 protected:
   const fd_state_machine &m_sm;
   tree m_arg;
-- 
2.25.1



More information about the Gcc-patches mailing list