From 8a9e8bbd7e402bb98c190163738f3a7b87784ceb Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Wed, 10 Jun 2015 10:37:21 -0400 Subject: [PATCH 14/35] Add selftests to tree.c Jeff approved an earlier version of this (as unittests/test-tree.c): https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03303.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 at the end of tree.c. gcc/ChangeLog: * tree.c: Include "selftest.h". (tree_test, integer_constants): New selftest. (tree_test, identifiers): New selftest. (tree_test, labels): New selftest. --- gcc/tree.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/gcc/tree.c b/gcc/tree.c index 5a1d167..35e819c 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -61,6 +61,7 @@ along with GCC; see the file COPYING3. If not see #include "builtins.h" #include "print-tree.h" #include "ipa-utils.h" +#include "selftest.h" /* Tree code classes. */ @@ -14179,4 +14180,50 @@ combined_fn_name (combined_fn fn) return internal_fn_name (as_internal_fn (fn)); } +#if CHECKING_P + +namespace { + +/* Verify that integer constants are sane. */ + +TEST (tree_test, integer_constants) +{ + ASSERT_TRUE (integer_type_node != NULL); + EXPECT_TRUE (build_int_cst (integer_type_node, 0) != NULL); + + tree type = integer_type_node; + + tree zero = build_zero_cst (type); + EXPECT_EQ (INTEGER_CST, TREE_CODE (zero)); + EXPECT_EQ (type, TREE_TYPE (zero)); + + tree one = build_int_cst (type, 1); + EXPECT_EQ (INTEGER_CST, TREE_CODE (one)); + EXPECT_EQ (type, TREE_TYPE (zero)); +} + +/* Verify identifiers. */ + +TEST (tree_test, identifiers) +{ + tree identifier = get_identifier ("foo"); + EXPECT_EQ (3, IDENTIFIER_LENGTH (identifier)); + EXPECT_STREQ ("foo", IDENTIFIER_POINTER (identifier)); +} + +/* Verify LABEL_DECL. */ + +TEST (tree_test, labels) +{ + tree identifier = get_identifier ("err"); + tree label_decl = build_decl (UNKNOWN_LOCATION, LABEL_DECL, + identifier, void_type_node); + EXPECT_EQ (-1, LABEL_DECL_UID (label_decl)); + EXPECT_FALSE (FORCED_LABEL (label_decl)); +} + +} // anon namespace + +#endif /* CHECKING_P */ + #include "gt-tree.h" -- 1.8.5.3