]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
analyzer: show value ranges in svalue::dump
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 6 May 2026 14:22:57 +0000 (10:22 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Wed, 6 May 2026 14:22:57 +0000 (10:22 -0400)
This patch adds value_range info where available to the various nodes
in svalue dumps, such as:

(gdb) call rhs2_sval->dump ()
(27): ‘long long unsigned int’: binop_svalue(bit_and_expr: ‘&’) value range: {[irange] long long unsigned int [0, 0]}
├─ (24): ‘long long unsigned int’: unaryop_svalue(nop_expr) value range: {[irange] long long unsigned int [0, 4294967295] MASK 0xffffffff VALUE 0x0}
│  ╰─ (22): ‘unsigned int’: initial_svalue value range: {[irange] unsigned int VARYING}
│     ╰─ m_reg: (21): ‘unsigned int’: decl_region(‘m’)
│        ╰─ parent: (4): globals
│           ╰─ parent: (0): root region
╰─ (26): ‘long long unsigned int’: constant_svalue (‘5497558138880’) value range: {[irange] long long unsigned int [54975581388805497558138880]}

where we can see that sval 27 has value range [0,0] and
where that comes from (due to being a bit_and_expr of non-overlapping
ranges from sval 24 and 26).

gcc/analyzer/ChangeLog:
* svalue.cc (svalue::make_dump_widget): Show value ranges in
svalue dumps.

gcc/ChangeLog:
* value-range.cc (value_range::print): New, based on
value_range::dump.
* value-range.h (value_range::print): New decl.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/analyzer/svalue.cc
gcc/value-range.cc
gcc/value-range.h

index fe22ae73dddaa9de09e637e97ec18ce9c935a6a6..1c0041ab75bb40b7e7062dfa904f49d620b45251 100644 (file)
@@ -227,6 +227,14 @@ svalue::make_dump_widget (const text_art::dump_widget_info &dwi,
 
   print_dump_widget_label (&pp);
 
+  value_range out;
+  if (maybe_get_value_range (out))
+    {
+      pp_printf (&pp, " value range: {"),
+       out.print (&pp);
+      pp_string (&pp, "}");
+    }
+
   std::unique_ptr<text_art::tree_widget> w
     (text_art::tree_widget::make (dwi, &pp));
 
index 657afa0acaa718d2c61f7689c35be30463569269..a1e5c805057c04aa1eb8e3af265859de3abedbe7 100644 (file)
@@ -157,6 +157,18 @@ value_range::dump (FILE *out) const
     fprintf (out, "NULL");
 }
 
+void
+value_range::print (pretty_printer *pp) const
+{
+  if (m_vrange)
+    {
+      vrange_printer vrange_pp (pp);
+      m_vrange->accept (vrange_pp);
+    }
+  else
+    pp_string (pp, "NULL");
+}
+
 DEBUG_FUNCTION void
 debug (const value_range &r)
 {
index eaf29236d99792873b1071ef72d891869efc510d..85deebab092d2206b7e8a3fe4bec78ee09c7f057 100644 (file)
@@ -792,6 +792,7 @@ public:
   operator vrange &();
   operator const vrange &() const;
   void dump (FILE *) const;
+  void print (pretty_printer *) const;
   static bool supports_type_p (const_tree type);
 
   tree type () { return m_vrange->type (); }