This patch silences a number of unused parameter warnings whilst
compiling both generic-match.c and gimple-match.c.  The problem is
that multiple (polymorphic) functions are generated for generic_simplify
and gimple_simplify, each handling tree codes with a specific number
of children.  Currently, there are no simplifications for tree codes
with four or five children, leading to functions with "empty" bodies
and unused function arguments.  This patch detects those cases, and
generates stub functions (with anonymous arguments) to silence these
warnings.

Previously, genmatch would generate:

static bool
gimple_simplify (gimple_match_op *res_op, gimple_seq *seq,
                 tree (*valueize)(tree) ATTRIBUTE_UNUSED,
                 code_helper code, const tree type, tree _p0, tree _p1, tree
_p2, tree _p3)
{
  switch (code.get_rep())
    {
    default:;
    }
  return false;
}

which results in:
 gimple_simplify (gimple_match_op *res_op, gimple_seq *seq,
 ^
gimple-match.c:130408:1: warning: unused parameter 'seq'
[-Wunused-parameter]
gimple-match.c:130408:1: warning: unused parameter 'type'
[-Wunused-parameter]
gimple-match.c:130408:1: warning: unused parameter '_p0'
[-Wunused-parameter]
gimple-match.c:130408:1: warning: unused parameter '_p1'
[-Wunused-parameter]
gimple-match.c:130408:1: warning: unused parameter '_p2'
[-Wunused-parameter]
gimple-match.c:130408:1: warning: unused parameter '_p3'
[-Wunused-parameter]
gimple-match.c:130420:1: warning: unused parameter 'res_op'
[-Wunused-parameter]

With this patch genmatch now generates:
static bool
gimple_simplify (gimple_match_op*, gimple_seq*,
                 tree (*)(tree), code_helper,
                 const tree, tree, tree, tree, tree)
{
  return false;
}

which has the same signature but no compilation warnings.

This patch has been tested on x86_64-pc-linux-gnu with a full
"make bootstrap" and "make -k check" with no new failures.
Ok for mainline?


2020-08-01  Roger Sayle  <ro...@nextmovesoftware.com>

        * gcc/genmatch.c (decision_tree::gen): Emit stub functions for
        tree code operand counts that have no simplifications.
        (main): Correct comment typo.

Thanks in advance,
Roger
--
Roger Sayle
NextMove Software
Cambridge, UK

diff --git a/gcc/genmatch.c b/gcc/genmatch.c
index 0a8cba6..022ad8d 100644
--- a/gcc/genmatch.c
+++ b/gcc/genmatch.c
@@ -3798,6 +3798,8 @@ decision_tree::gen (FILE *f, bool gimple)
 
   for (unsigned n = 1; n <= 5; ++n)
     {
+      bool has_kids_p = false;
+
       /* First generate split-out functions.  */
       for (unsigned j = 0; j < root->kids.length (); j++)
        {
@@ -3836,6 +3838,32 @@ decision_tree::gen (FILE *f, bool gimple)
          else
            fprintf (f, "  return NULL_TREE;\n");
          fprintf (f, "}\n");
+         has_kids_p = true;
+       }
+
+      /* If this main entry has no children, avoid generating code
+        with compiler warnings, by generating a simple stub.  */
+      if (! has_kids_p)
+       {
+         if (gimple)
+           fprintf (f, "\nstatic bool\n"
+                       "gimple_simplify (gimple_match_op*, gimple_seq*,\n"
+                       "                 tree (*)(tree), code_helper,\n"
+                       "                 const tree");
+         else
+           fprintf (f, "\ntree\n"
+                       "generic_simplify (location_t, enum tree_code,\n"
+                       "                  const tree");
+         for (unsigned i = 0; i < n; ++i)
+           fprintf (f, ", tree");
+         fprintf (f, ")\n");
+         fprintf (f, "{\n");
+         if (gimple)
+           fprintf (f, "  return false;\n");
+         else
+           fprintf (f, "  return NULL_TREE;\n");
+         fprintf (f, "}\n");
+         continue;
        }
 
       /* Then generate the main entry with the outermost switch and
@@ -5061,7 +5089,7 @@ round_alloc_size (size_t s)
 }
 
 
-/* The genmatch generator progam.  It reads from a pattern description
+/* The genmatch generator program.  It reads from a pattern description
    and outputs GIMPLE or GENERIC IL matching and simplification routines.  */
 
 int

Reply via email to