gcc/
[official-gcc.git] / gcc / rtl-tests.c
blob3e9ebae02bbcd1b5a2365ecca91754017f7c9694
1 /* Unit tests for RTL-handling.
2 Copyright (C) 2015-2016 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "opts.h"
25 #include "signop.h"
26 #include "hash-set.h"
27 #include "fixed-value.h"
28 #include "alias.h"
29 #include "flags.h"
30 #include "symtab.h"
31 #include "tree-core.h"
32 #include "stor-layout.h"
33 #include "tree.h"
34 #include "stringpool.h"
35 #include "stor-layout.h"
36 #include "rtl.h"
37 #include "pretty-print.h"
38 #include "cfgbuild.h"
39 #include "print-rtl.h"
40 #include "selftest.h"
41 #include "function.h"
42 #include "emit-rtl.h"
44 #if CHECKING_P
46 namespace selftest {
48 /* Verify that PAT is printed as EXPECTED. Helper function for
49 selftests. */
51 static void
52 verify_print_pattern (const char *expected, rtx pat)
54 pretty_printer pp;
55 print_pattern (&pp, pat, 1);
56 ASSERT_STREQ (expected, pp_formatted_text (&pp));
59 /* Unit testing of "single_set". */
61 static void
62 test_single_set ()
64 /* A label is not a SET. */
65 ASSERT_EQ (NULL_RTX, single_set (gen_label_rtx ()));
67 /* An unconditional jump insn is a single SET. */
68 rtx set_pc = gen_rtx_SET (pc_rtx,
69 gen_rtx_LABEL_REF (VOIDmode,
70 gen_label_rtx ()));
71 rtx_insn *jump_insn = emit_jump_insn (set_pc);
72 ASSERT_EQ (set_pc, single_set (jump_insn));
74 /* etc */
77 /* Construct an unconditional jump to a label, and verify that
78 various properties of it are sane. */
80 static void
81 test_uncond_jump ()
83 rtx_insn *label = gen_label_rtx ();
84 rtx jump_pat = gen_rtx_SET (pc_rtx,
85 gen_rtx_LABEL_REF (VOIDmode,
86 label));
87 ASSERT_EQ (SET, jump_pat->code);
88 ASSERT_EQ (LABEL_REF, SET_SRC (jump_pat)->code);
89 ASSERT_EQ (label, LABEL_REF_LABEL (SET_SRC (jump_pat)));
90 ASSERT_EQ (PC, SET_DEST (jump_pat)->code);
92 verify_print_pattern ("pc=L0", jump_pat);
94 rtx_insn *jump_insn = emit_jump_insn (jump_pat);
95 ASSERT_FALSE (any_condjump_p (jump_insn));
96 ASSERT_TRUE (any_uncondjump_p (jump_insn));
97 ASSERT_TRUE (pc_set (jump_insn));
98 ASSERT_TRUE (simplejump_p (jump_insn));
99 ASSERT_TRUE (onlyjump_p (jump_insn));
100 ASSERT_TRUE (control_flow_insn_p (jump_insn));
103 /* Run all of the selftests within this file. */
105 void
106 rtl_tests_c_tests ()
108 test_single_set ();
109 test_uncond_jump ();
111 /* Purge state. */
112 set_first_insn (NULL);
113 set_last_insn (NULL);
116 } // namespace selftest
117 #endif /* #if CHECKING_P */