[PATCH 19/21] Add rtl-tests.c

David Malcolm dmalcolm@redhat.com
Wed Jun 1 21:22:00 GMT 2016


Jeff approved an earlier version of this (as
unittests/test-rtl.c):
 https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03302.html
> OK if/when prereqs are approved. Minor twiddling if we end up
> moving it elsewhere or standardizing/reducing header files is
>pre-approved.

This version puts the tests in gcc/rtl-tests.c.

gcc/ChangeLog:
	* rtl-tests.c: New file.
---
 gcc/rtl-tests.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 98 insertions(+)
 create mode 100644 gcc/rtl-tests.c

diff --git a/gcc/rtl-tests.c b/gcc/rtl-tests.c
new file mode 100644
index 0000000..611d82a
--- /dev/null
+++ b/gcc/rtl-tests.c
@@ -0,0 +1,98 @@
+/* Unit tests for RTL-handling.
+   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 "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 "pretty-print.h"
+#include "cfgbuild.h"
+#include "print-rtl.h"
+#include "selftest.h"
+
+#if CHECKING_P
+
+namespace {
+
+class rtl_test : public ::selftest::test
+{
+ protected:
+  void
+  verify_print_pattern (const char *expected, rtx pat)
+  {
+    pretty_printer pp;
+    print_pattern (&pp, pat, 1);
+    EXPECT_STREQ (expected, pp_formatted_text (&pp));
+  }
+};
+
+/* Unit testing of "single_set".  */
+TEST_F (rtl_test, test_single_set)
+{
+  /* A label is not a SET.  */
+  EXPECT_EQ (NULL_RTX, single_set (gen_label_rtx ()));
+
+  /* An unconditional jump insn is a single SET.  */
+  rtx set_pc = gen_rtx_SET (pc_rtx,
+			    gen_rtx_LABEL_REF (VOIDmode,
+					       gen_label_rtx ()));
+  rtx_insn *jump_insn = emit_jump_insn (set_pc);
+  EXPECT_EQ (set_pc, single_set (jump_insn));
+
+  /* etc */
+}
+
+TEST_F (rtl_test, uncond_jump)
+{
+  rtx_insn *label = gen_label_rtx ();
+  rtx jump_pat = gen_rtx_SET (pc_rtx,
+			      gen_rtx_LABEL_REF (VOIDmode,
+						 label));
+  EXPECT_EQ (SET, jump_pat->code);
+  EXPECT_EQ (LABEL_REF, SET_SRC (jump_pat)->code);
+  EXPECT_EQ (label, LABEL_REF_LABEL (SET_SRC (jump_pat)));
+  EXPECT_EQ (PC, SET_DEST (jump_pat)->code);
+
+  verify_print_pattern ("pc=L0", jump_pat);
+
+  rtx_insn *jump_insn = emit_jump_insn (jump_pat);
+  EXPECT_FALSE (any_condjump_p (jump_insn));
+  EXPECT_TRUE (any_uncondjump_p (jump_insn));
+  EXPECT_TRUE (pc_set (jump_insn));
+  EXPECT_TRUE (simplejump_p (jump_insn));
+  EXPECT_TRUE (onlyjump_p (jump_insn));
+  EXPECT_TRUE (control_flow_insn_p (jump_insn));
+}
+
+}  /* anon namespace.  */
+
+#endif /* #if CHECKING_P */
-- 
1.8.5.3



More information about the Gcc-patches mailing list