summaryrefslogtreecommitdiff
path: root/gcc/gimple.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2016-06-06 17:11:30 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2016-06-06 17:11:30 +0000
commitd9b950dd440fe2029a111cda56add2c9e91123b9 (patch)
tree63fc70ab85f16020285e16504429ce186042a4da /gcc/gimple.c
parentdbc6221fe5aa38017bb5818aa28257360b15f3b6 (diff)
Selftest framework
gcc/ChangeLog: * Makefile.in (OBJS): Add function-tests.o, hash-map-tests.o, hash-set-tests.o, rtl-tests.o, selftest-run-tests.o. (OBJS-libcommon): Add selftest.o. (OBJS-libcommon-target): Add selftest.o. (all.internal): Add "selftest". (all.cross): Likewise. (selftest): New phony target. (s-selftest): New target. (selftest-gdb): New phony target. (COLLECT2_OBJS): Add selftest.o. * bitmap.c: Include "selftest.h". (selftest::test_gc_alloc): New function. (selftest::test_set_range): New function. (selftest::test_clear_bit_in_middle): New function. (selftest::test_copying): New function. (selftest::test_bitmap_single_bit_set_p): New function. (selftest::bitmap_c_tests): New function. * common.opt (fself-test): New. * diagnostic-show-locus.c: Include "selftest.h". (make_range): New function. (test_range_contains_point_for_single_point): New function. (test_range_contains_point_for_single_line): New function. (test_range_contains_point_for_multiple_lines): New function. (assert_eq): New function. (test_get_line_width_without_trailing_whitespace): New function. (selftest::diagnostic_show_locus_c_tests): New function. * et-forest.c: Include "selftest.h". (selftest::test_single_node): New function. (selftest::test_simple_tree): New function. (selftest::test_disconnected_nodes): New function. (selftest::et_forest_c_tests): New function. * fold-const.c: Include "selftest.h". (selftest::assert_binop_folds_to_const): New function. (selftest::assert_binop_folds_to_nonlvalue): New function. (selftest::test_arithmetic_folding): New function. (selftest::fold_const_c_tests): New function. * function-tests.c: New file. * gimple.c: Include "selftest.h". Include "gimple-pretty-print.h". (selftest::verify_gimple_pp): New function. (selftest::test_assign_single): New function. (selftest::test_assign_binop): New function. (selftest::test_nop_stmt): New function. (selftest::test_return_stmt): New function. (selftest::test_return_without_value): New function. (selftest::gimple_c_tests): New function. * hash-map-tests.c: New file. * hash-set-tests.c: New file. * input.c: Include "selftest.h". (selftest::assert_loceq): New function. (selftest::test_accessing_ordinary_linemaps): New function. (selftest::test_unknown_location): New function. (selftest::test_builtins): New function. (selftest::test_reading_source_line): New function. (selftest::input_c_tests): New function. * rtl-tests.c: New file. * selftest-run-tests.c: New file. * selftest.c: New file. * selftest.h: New file. * spellcheck.c: Include "selftest.h". (selftest::levenshtein_distance_unit_test_oneway): New function, adapted from testsuite/gcc.dg/plugin/levenshtein_plugin.c. (selftest::levenshtein_distance_unit_test): Likewise. (selftest::spellcheck_c_tests): Likewise. * toplev.c: Include selftest.h. (toplev::run_self_tests): New. (toplev::main): Handle -fself-test. * toplev.h (toplev::run_self_tests): New. * tree.c: Include "selftest.h". (selftest::test_integer_constants): New function. (selftest::test_identifiers): New function. (selftest::test_labels): New function. (selftest::tree_c_tests): New function. * tree-cfg.c: Include "selftest.h". (selftest::push_fndecl): New function. (selftest::test_linear_chain): New function. (selftest::test_diamond): New function. (selftest::test_fully_connected): New function. (selftest::tree_cfg_c_tests): New function. * vec.c: Include "selftest.h". (selftest::safe_push_range): New function. (selftest::test_quick_push): New function. (selftest::test_safe_push): New function. (selftest::test_truncate): New function. (selftest::test_safe_grow_cleared): New function. (selftest::test_pop): New function. (selftest::test_safe_insert): New function. (selftest::test_ordered_remove): New function. (selftest::test_unordered_remove): New function. (selftest::test_block_remove): New function. (selftest::reverse_cmp): New function. (selftest::test_qsort): New function. (selftest::vec_c_tests): New function.c. * wide-int.cc: Include selftest.h and wide-int-print.h. (selftest::from_int <wide_int>): New function. (selftest::from_int <offset_int>): New function. (selftest::from_int <widest_int>): New function. (selftest::assert_deceq): New function. (selftest::assert_hexeq): New function. (selftest::test_printing <VALUE_TYPE>): New function template. (selftest::test_ops <VALUE_TYPE>): New function template. (selftest::test_comparisons <VALUE_TYPE>): New function template. (selftest::run_all_wide_int_tests <VALUE_TYPE>): New function template. (selftest::wide_int_cc_tests): New function. gcc/testsuite/ChangeLog: * gcc.dg/plugin/levenshtein-test-1.c: Delete. * gcc.dg/plugin/levenshtein_plugin.c: Delete. * gcc.dg/plugin/plugin.exp (plugin_test_list): Remove the above. From-SVN: r237144
Diffstat (limited to 'gcc/gimple.c')
-rw-r--r--gcc/gimple.c137
1 files changed, 137 insertions, 0 deletions
diff --git a/gcc/gimple.c b/gcc/gimple.c
index 75a1ed8ee0b..178c1d3a517 100644
--- a/gcc/gimple.c
+++ b/gcc/gimple.c
@@ -38,6 +38,8 @@ along with GCC; see the file COPYING3. If not see
#include "gimple-walk.h"
#include "gimplify.h"
#include "target.h"
+#include "selftest.h"
+#include "gimple-pretty-print.h"
/* All the tuples have their operand vector (if present) at the very bottom
@@ -3022,3 +3024,138 @@ maybe_remove_unused_call_args (struct function *fn, gimple *stmt)
update_stmt_fn (fn, stmt);
}
}
+
+#if CHECKING_P
+
+namespace selftest {
+
+/* Selftests for core gimple structures. */
+
+/* Verify that STMT is pretty-printed as EXPECTED.
+ Helper function for selftests. */
+
+static void
+verify_gimple_pp (const char *expected, gimple *stmt)
+{
+ pretty_printer pp;
+ pp_gimple_stmt_1 (&pp, stmt, 0 /* spc */, 0 /* flags */);
+ ASSERT_STREQ (expected, pp_formatted_text (&pp));
+}
+
+/* Build a GIMPLE_ASSIGN equivalent to
+ tmp = 5;
+ and verify various properties of it. */
+
+static void
+test_assign_single ()
+{
+ 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);
+
+ ASSERT_TRUE (is_gimple_assign (stmt));
+ ASSERT_EQ (lhs, gimple_assign_lhs (stmt));
+ ASSERT_EQ (lhs, gimple_get_lhs (stmt));
+ ASSERT_EQ (rhs, gimple_assign_rhs1 (stmt));
+ ASSERT_EQ (NULL, gimple_assign_rhs2 (stmt));
+ ASSERT_EQ (NULL, gimple_assign_rhs3 (stmt));
+ ASSERT_TRUE (gimple_assign_single_p (stmt));
+ ASSERT_EQ (INTEGER_CST, gimple_assign_rhs_code (stmt));
+}
+
+/* Build a GIMPLE_ASSIGN equivalent to
+ tmp = a * b;
+ and verify various properties of it. */
+
+static void
+test_assign_binop ()
+{
+ 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);
+
+ ASSERT_TRUE (is_gimple_assign (stmt));
+ ASSERT_EQ (lhs, gimple_assign_lhs (stmt));
+ ASSERT_EQ (lhs, gimple_get_lhs (stmt));
+ ASSERT_EQ (a, gimple_assign_rhs1 (stmt));
+ ASSERT_EQ (b, gimple_assign_rhs2 (stmt));
+ ASSERT_EQ (NULL, gimple_assign_rhs3 (stmt));
+ ASSERT_FALSE (gimple_assign_single_p (stmt));
+ ASSERT_EQ (MULT_EXPR, gimple_assign_rhs_code (stmt));
+}
+
+/* Build a GIMPLE_NOP and verify various properties of it. */
+
+static void
+test_nop_stmt ()
+{
+ gimple *stmt = gimple_build_nop ();
+ verify_gimple_pp ("GIMPLE_NOP", stmt);
+ ASSERT_EQ (GIMPLE_NOP, gimple_code (stmt));
+ ASSERT_EQ (NULL, gimple_get_lhs (stmt));
+ ASSERT_FALSE (gimple_assign_single_p (stmt));
+}
+
+/* Build a GIMPLE_RETURN equivalent to
+ return 7;
+ and verify various properties of it. */
+
+static void
+test_return_stmt ()
+{
+ tree type = integer_type_node;
+ tree val = build_int_cst (type, 7);
+ greturn *stmt = gimple_build_return (val);
+ verify_gimple_pp ("return 7;", stmt);
+
+ ASSERT_EQ (GIMPLE_RETURN, gimple_code (stmt));
+ ASSERT_EQ (NULL, gimple_get_lhs (stmt));
+ ASSERT_EQ (val, gimple_return_retval (stmt));
+ ASSERT_FALSE (gimple_assign_single_p (stmt));
+}
+
+/* Build a GIMPLE_RETURN equivalent to
+ return;
+ and verify various properties of it. */
+
+static void
+test_return_without_value ()
+{
+ greturn *stmt = gimple_build_return (NULL);
+ verify_gimple_pp ("return;", stmt);
+
+ ASSERT_EQ (GIMPLE_RETURN, gimple_code (stmt));
+ ASSERT_EQ (NULL, gimple_get_lhs (stmt));
+ ASSERT_EQ (NULL, gimple_return_retval (stmt));
+ ASSERT_FALSE (gimple_assign_single_p (stmt));
+}
+
+/* Run all of the selftests within this file. */
+
+void
+gimple_c_tests ()
+{
+ test_assign_single ();
+ test_assign_binop ();
+ test_nop_stmt ();
+ test_return_stmt ();
+ test_return_without_value ();
+}
+
+} // namespace selftest
+
+
+#endif /* CHECKING_P */