]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/rtl-tests.c
Selftest framework
[thirdparty/gcc.git] / gcc / rtl-tests.c
CommitLineData
d9b950dd
DM
1/* Unit tests for RTL-handling.
2 Copyright (C) 2015-2016 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
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"
43
44#if CHECKING_P
45
46namespace selftest {
47
48/* Verify that PAT is printed as EXPECTED. Helper function for
49 selftests. */
50
51static void
52verify_print_pattern (const char *expected, rtx pat)
53{
54 pretty_printer pp;
55 print_pattern (&pp, pat, 1);
56 ASSERT_STREQ (expected, pp_formatted_text (&pp));
57}
58
59/* Unit testing of "single_set". */
60
61static void
62test_single_set ()
63{
64 /* A label is not a SET. */
65 ASSERT_EQ (NULL_RTX, single_set (gen_label_rtx ()));
66
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));
73
74 /* etc */
75}
76
77/* Construct an unconditional jump to a label, and verify that
78 various properties of it are sane. */
79
80static void
81test_uncond_jump ()
82{
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);
91
92 verify_print_pattern ("pc=L0", jump_pat);
93
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));
101}
102
103/* Run all of the selftests within this file. */
104
105void
106rtl_tests_c_tests ()
107{
108 test_single_set ();
109 test_uncond_jump ();
110
111 /* Purge state. */
112 set_first_insn (NULL);
113 set_last_insn (NULL);
114}
115
116} // namespace selftest
117#endif /* #if CHECKING_P */