This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 13/15] Add selftests to tree.c
- From: David Malcolm <dmalcolm at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Bernd Schmidt <bschmidt at redhat dot com>, Jeff Law <law at redhat dot com>, David Malcolm <dmalcolm at redhat dot com>
- Date: Thu, 19 Nov 2015 12:04:57 -0500
- Subject: [PATCH 13/15] Add selftests to tree.c
- Authentication-results: sourceware.org; auth=none
- References: <564A1DAB dot 1030700 at redhat dot com> <1447952699-40820-1-git-send-email-dmalcolm at redhat dot com>
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 d5a71a3..6ed1914 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. */
@@ -13951,4 +13952,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