* [pushed] analyzer: add SARIF property bag to -Wanalyzer-infinite-loop
@ 2024-04-10 20:56 David Malcolm
0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2024-04-10 20:56 UTC (permalink / raw)
To: gcc-patches; +Cc: David Malcolm
Tested lightly by hand.
Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Successful run of analyzer integration tests on x86_64-pc-linux-gnu.
Pushed to trunk as r14-9901-g107b0e63be023c.
gcc/analyzer/ChangeLog:
* infinite-loop.cc: Include "diagnostic-format-sarif.h".
(infinite_loop::to_json): New.
(infinite_loop_diagnostic::maybe_add_sarif_properties): New.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
gcc/analyzer/infinite-loop.cc | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/gcc/analyzer/infinite-loop.cc b/gcc/analyzer/infinite-loop.cc
index 296489b1146d..e277a8384a04 100644
--- a/gcc/analyzer/infinite-loop.cc
+++ b/gcc/analyzer/infinite-loop.cc
@@ -63,6 +63,7 @@ along with GCC; see the file COPYING3. If not see
#include "analyzer/checker-path.h"
#include "analyzer/feasible-graph.h"
#include "make-unique.h"
+#include "diagnostic-format-sarif.h"
/* A bundle of data characterizing a particular infinite loop
identified within the exploded graph. */
@@ -105,6 +106,18 @@ struct infinite_loop
&& m_loc == other.m_loc);
}
+ json::object *
+ to_json () const
+ {
+ json::object *loop_obj = new json::object ();
+ loop_obj->set_integer ("enode", m_enode.m_index);
+ json::array *edge_arr = new json::array ();
+ for (auto eedge : m_eedge_vec)
+ edge_arr->append (eedge->to_json ());
+ loop_obj->set ("eedges", edge_arr);
+ return loop_obj;
+ }
+
const exploded_node &m_enode;
location_t m_loc;
std::vector<const exploded_edge *> m_eedge_vec;
@@ -297,6 +310,15 @@ public:
}
}
+ void maybe_add_sarif_properties (sarif_object &result_obj)
+ const final override
+ {
+ sarif_property_bag &props = result_obj.get_or_create_properties ();
+#define PROPERTY_PREFIX "gcc/analyzer/infinite_loop_diagnostic/"
+ props.set (PROPERTY_PREFIX "inf_loop", m_inf_loop->to_json ());
+#undef PROPERTY_PREFIX
+ }
+
private:
std::unique_ptr<infinite_loop> m_inf_loop;
};
--
2.26.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-04-10 20:56 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-10 20:56 [pushed] analyzer: add SARIF property bag to -Wanalyzer-infinite-loop David Malcolm
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).