On Wed, Oct 28, 2015 at 1:34 PM, Richard Biener
<richard.guent...@gmail.com> wrote:
> On Tue, Oct 27, 2015 at 8:49 PM, David Malcolm <dmalc...@redhat.com> wrote:
>> gcc/testsuite/ChangeLog:
>>         * unittests/test-gimple.c: New file.
>
> I fear that keeping tests like this up-to-date and working is more of
> a headache than
> the value we get from it.

So - with our testsuite and passes we have the issues that we'd like
to have regression
tests that nail down the IL input to a specific pass.  That rots over
time (obviously) so
many tests are no longer testing what they are supposed to test.

Some years ago I proposed -Otest to make the input into passes a little bit more
stable (basically run only a single pass).  It requires the desired
pass input to
be created from the lowering stages only of course (you could enable more than
one pass but then things get less stable again).

Ideally we'd get progress with the GIMPLE FE up to the point that textual
input to passes works (we need pass manager support for this as well,
of course).

I'm fine with doing your kind of unit tests for infrastructure things,
but test-gimple.c at
least looks very odd.

Richard.

> Richard.
>
>> ---
>>  gcc/testsuite/unittests/test-gimple.c | 178 
>> ++++++++++++++++++++++++++++++++++
>>  1 file changed, 178 insertions(+)
>>  create mode 100644 gcc/testsuite/unittests/test-gimple.c
>>
>> diff --git a/gcc/testsuite/unittests/test-gimple.c 
>> b/gcc/testsuite/unittests/test-gimple.c
>> new file mode 100644
>> index 0000000..b0fa9f4
>> --- /dev/null
>> +++ b/gcc/testsuite/unittests/test-gimple.c
>> @@ -0,0 +1,178 @@
>> +/* Unit tests for gimple.
>> +   Copyright (C) 2015 Free Software Foundation, Inc.
>> +
>> +This file is part of GCC.
>> +
>> +GCC is free software; you can redistribute it and/or modify it under
>> +the terms of the GNU General Public License as published by the Free
>> +Software Foundation; either version 3, or (at your option) any later
>> +version.
>> +
>> +GCC is distributed in the hope that it will be useful, but WITHOUT ANY
>> +WARRANTY; without even the implied warranty of MERCHANTABILITY or
>> +FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
>> +for more details.
>> +
>> +You should have received a copy of the GNU General Public License
>> +along with GCC; see the file COPYING3.  If not see
>> +<http://www.gnu.org/licenses/>.  */
>> +
>> +#include "config.h"
>> +#include "gtest/gtest.h"
>> +#include "system.h"
>> +#include "coretypes.h"
>> +#include "tm.h"
>> +#include "opts.h"
>> +#include "signop.h"
>> +#include "hash-set.h"
>> +#include "fixed-value.h"
>> +#include "alias.h"
>> +#include "flags.h"
>> +#include "symtab.h"
>> +#include "tree-core.h"
>> +#include "stor-layout.h"
>> +#include "tree.h"
>> +#include "stringpool.h"
>> +#include "stor-layout.h"
>> +#include "rtl.h"
>> +#include "predict.h"
>> +#include "vec.h"
>> +#include "hashtab.h"
>> +#include "hash-set.h"
>> +#include "machmode.h"
>> +#include "hard-reg-set.h"
>> +#include "input.h"
>> +#include "function.h"
>> +#include "dominance.h"
>> +#include "cfg.h"
>> +#include "cfganal.h"
>> +#include "basic-block.h"
>> +#include "tree-ssa-alias.h"
>> +#include "internal-fn.h"
>> +#include "gimple-fold.h"
>> +#include "gimple-expr.h"
>> +#include "toplev.h"
>> +#include "print-tree.h"
>> +#include "tree-iterator.h"
>> +#include "gimplify.h"
>> +#include "tree-cfg.h"
>> +#include "basic-block.h"
>> +#include "double-int.h"
>> +#include "alias.h"
>> +#include "symtab.h"
>> +#include "wide-int.h"
>> +#include "inchash.h"
>> +#include "tree.h"
>> +#include "fold-const.h"
>> +#include "stor-layout.h"
>> +#include "stmt.h"
>> +#include "hash-table.h"
>> +#include "tree-ssa-alias.h"
>> +#include "internal-fn.h"
>> +#include "gimple-expr.h"
>> +#include "is-a.h"
>> +#include "gimple.h"
>> +#include "tree-pass.h"
>> +#include "context.h"
>> +#include "hash-map.h"
>> +#include "plugin-api.h"
>> +#include "ipa-ref.h"
>> +#include "cgraph.h"
>> +#include "gimple-pretty-print.h"
>> +
>> +namespace {
>> +
>> +class gimple_test : public ::testing::Test
>> +{
>> + protected:
>> +  void
>> +  verify_gimple_pp (const char *expected, gimple *stmt)
>> +  {
>> +    pretty_printer pp;
>> +    pp_gimple_stmt_1 (&pp, stmt, 0 /* spc */, 0 /* flags */);
>> +    EXPECT_STREQ (expected, pp_formatted_text (&pp));
>> +  }
>> +};
>> +
>> +TEST_F (gimple_test, assign_single)
>> +{
>> +  /* Build "tmp = 5;"  */
>> +  tree type = integer_type_node;
>> +  tree lhs = build_decl (UNKNOWN_LOCATION, VAR_DECL,
>> +                        get_identifier ("tmp"),
>> +                        type);
>> +  tree rhs = build_int_cst (type, 5);
>> +  gassign *stmt = gimple_build_assign (lhs, rhs);
>> +  verify_gimple_pp ("tmp = 5;", stmt);
>> +
>> +  EXPECT_TRUE (is_gimple_assign (stmt));
>> +  EXPECT_EQ (lhs, gimple_assign_lhs (stmt));
>> +  EXPECT_EQ (lhs, gimple_get_lhs (stmt));
>> +  EXPECT_EQ (rhs, gimple_assign_rhs1 (stmt));
>> +  EXPECT_EQ (NULL, gimple_assign_rhs2 (stmt));
>> +  EXPECT_EQ (NULL, gimple_assign_rhs3 (stmt));
>> +  EXPECT_TRUE (gimple_assign_single_p (stmt));
>> +  EXPECT_EQ (INTEGER_CST, gimple_assign_rhs_code (stmt));
>> +}
>> +
>> +TEST_F (gimple_test, assign_binop)
>> +{
>> +  /* Build "tmp = a + b;"  */
>> +  tree type = integer_type_node;
>> +  tree lhs = build_decl (UNKNOWN_LOCATION, VAR_DECL,
>> +                        get_identifier ("tmp"),
>> +                        type);
>> +  tree a = build_decl (UNKNOWN_LOCATION, VAR_DECL,
>> +                      get_identifier ("a"),
>> +                      type);
>> +  tree b = build_decl (UNKNOWN_LOCATION, VAR_DECL,
>> +                      get_identifier ("b"),
>> +                      type);
>> +  gassign *stmt = gimple_build_assign (lhs, MULT_EXPR, a, b);
>> +  verify_gimple_pp ("tmp = a * b;", stmt);
>> +
>> +  EXPECT_TRUE (is_gimple_assign (stmt));
>> +  EXPECT_EQ (lhs, gimple_assign_lhs (stmt));
>> +  EXPECT_EQ (lhs, gimple_get_lhs (stmt));
>> +  EXPECT_EQ (a, gimple_assign_rhs1 (stmt));
>> +  EXPECT_EQ (b, gimple_assign_rhs2 (stmt));
>> +  EXPECT_EQ (NULL, gimple_assign_rhs3 (stmt));
>> +  EXPECT_FALSE (gimple_assign_single_p (stmt));
>> +  EXPECT_EQ (MULT_EXPR, gimple_assign_rhs_code (stmt));
>> +}
>> +
>> +TEST_F (gimple_test, nop_stmt)
>> +{
>> +  gimple *stmt = gimple_build_nop ();
>> +  verify_gimple_pp ("GIMPLE_NOP", stmt);
>> +  EXPECT_EQ (GIMPLE_NOP, gimple_code (stmt));
>> +  EXPECT_EQ (NULL, gimple_get_lhs (stmt));
>> +  EXPECT_FALSE (gimple_assign_single_p (stmt));
>> +}
>> +
>> +TEST_F (gimple_test, return_stmt)
>> +{
>> +  /* Build "return 7;"  */
>> +  tree type = integer_type_node;
>> +  tree val = build_int_cst (type, 7);
>> +  greturn *stmt = gimple_build_return (val);
>> +  verify_gimple_pp ("return 7;", stmt);
>> +
>> +  EXPECT_EQ (GIMPLE_RETURN, gimple_code (stmt));
>> +  EXPECT_EQ (NULL, gimple_get_lhs (stmt));
>> +  EXPECT_EQ (val, gimple_return_retval (stmt));
>> +  EXPECT_FALSE (gimple_assign_single_p (stmt));
>> +}
>> +
>> +TEST_F (gimple_test, return_without_value)
>> +{
>> +  greturn *stmt = gimple_build_return (NULL);
>> +  verify_gimple_pp ("return;", stmt);
>> +
>> +  EXPECT_EQ (GIMPLE_RETURN, gimple_code (stmt));
>> +  EXPECT_EQ (NULL, gimple_get_lhs (stmt));
>> +  EXPECT_EQ (NULL, gimple_return_retval (stmt));
>> +  EXPECT_FALSE (gimple_assign_single_p (stmt));
>> +}
>> +
>> +}  /* anon namespace.  */
>> --
>> 1.8.5.3
>>

Reply via email to