This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 09/16] Add test-gimple.c to unittests
- From: David Malcolm <dmalcolm at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: David Malcolm <dmalcolm at redhat dot com>
- Date: Tue, 27 Oct 2015 15:49:08 -0400
- Subject: [PATCH 09/16] Add test-gimple.c to unittests
- Authentication-results: sourceware.org; auth=none
- References: <5589B2FB dot 8010500 at redhat dot com> <1445975355-37660-1-git-send-email-dmalcolm at redhat dot com>
gcc/testsuite/ChangeLog:
* unittests/test-gimple.c: New file.
---
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