[committed] analyzer: tweak dumping of min_expr/max_expr

Message ID 20210721212659.454047-1-dmalcolm@redhat.com
State New
Headers show
Series
  • [committed] analyzer: tweak dumping of min_expr/max_expr
Related show

Commit Message

Ian Lance Taylor via Gcc-patches July 21, 2021, 9:26 p.m.
Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as dcdf6bb24e5f113f2bb9298588105a071bddf50f.

gcc/analyzer/ChangeLog:
	* svalue.cc (infix_p): New.
	(binop_svalue::dump_to_pp): Use it to print MIN_EXPR and MAX_EXPR
	in prefix form, rather than infix.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>

---
 gcc/analyzer/svalue.cc | 39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)

-- 
2.26.3

Patch

diff --git a/gcc/analyzer/svalue.cc b/gcc/analyzer/svalue.cc
index 094c7256818..a1e6f50b7d7 100644
--- a/gcc/analyzer/svalue.cc
+++ b/gcc/analyzer/svalue.cc
@@ -1053,6 +1053,21 @@  unaryop_svalue::maybe_fold_bits_within (tree type,
 
 /* class binop_svalue : public svalue.  */
 
+/* Return whether OP be printed as an infix operator.  */
+
+static bool
+infix_p (enum tree_code op)
+{
+  switch (op)
+    {
+    default:
+      return true;
+    case MAX_EXPR:
+    case MIN_EXPR:
+      return false;
+    }
+}
+
 /* Implementation of svalue::dump_to_pp vfunc for binop_svalue.  */
 
 void
@@ -1060,11 +1075,25 @@  binop_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
 {
   if (simple)
     {
-      pp_character (pp, '(');
-      m_arg0->dump_to_pp (pp, simple);
-      pp_string (pp, op_symbol_code (m_op));
-      m_arg1->dump_to_pp (pp, simple);
-      pp_character (pp, ')');
+      if (infix_p (m_op))
+	{
+	  /* Print "(A OP B)".  */
+	  pp_character (pp, '(');
+	  m_arg0->dump_to_pp (pp, simple);
+	  pp_string (pp, op_symbol_code (m_op));
+	  m_arg1->dump_to_pp (pp, simple);
+	  pp_character (pp, ')');
+	}
+      else
+	{
+	  /* Print "OP(A, B)".  */
+	  pp_string (pp, op_symbol_code (m_op));
+	  pp_character (pp, '(');
+	  m_arg0->dump_to_pp (pp, simple);
+	  pp_string (pp, ", ");
+	  m_arg1->dump_to_pp (pp, simple);
+	  pp_character (pp, ')');
+	}
     }
   else
     {