From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 84406 invoked by alias); 1 Jun 2016 21:23:03 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 84365 invoked by uid 89); 1 Jun 2016 21:23:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.2 spammy=var_decl, HX-HELO:eggs.gnu.org, Hx-spam-relays-external:208.118.235.92, H*RU:208.118.235.92 X-HELO: eggs.gnu.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (208.118.235.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 01 Jun 2016 21:22:54 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8D9d-0007vW-1f for gcc-patches@gcc.gnu.org; Wed, 01 Jun 2016 16:54:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43844) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8D9c-0007vN-QI for gcc-patches@gcc.gnu.org; Wed, 01 Jun 2016 16:54:16 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 540707F6B9 for ; Wed, 1 Jun 2016 20:54:16 +0000 (UTC) Received: from c64.redhat.com (vpn-239-103.phx2.redhat.com [10.3.239.103]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u51Ks4WY027176; Wed, 1 Jun 2016 16:54:15 -0400 From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: Bernd Schmidt , Jeff Law , David Malcolm Subject: [PATCH 15/21] Add selftests to gimple.c Date: Wed, 01 Jun 2016 21:23:00 -0000 Message-Id: <1464816003-35862-16-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1464816003-35862-1-git-send-email-dmalcolm@redhat.com> References: <1447952699-40820-1-git-send-email-dmalcolm@redhat.com> <1464816003-35862-1-git-send-email-dmalcolm@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-IsSubscribed: yes X-SW-Source: 2016-06/txt/msg00103.txt.bz2 Jeff approved an earlier version of this (as unittests/test-gimple.c): https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03304.html > Comment indicates addition. But code actually generates a > MULT_EXPR. Please fix. Fixed > 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 moves the tests into gimple.c. gcc/ChangeLog: * gimple.c: Include "selftest.h". Include "gimple-pretty-print.h". (class gimple_test): New subclass. (gimple_test, assign_single): New selftest. (gimple_test, assign_binop): New selftest. (gimple_test, nop_stmt): New selftest. (gimple_test, return_stmt): New selftest. (gimple_test, return_without_value): New selftest. --- gcc/gimple.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/gcc/gimple.c b/gcc/gimple.c index d822fab..b5d7391 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 @@ -3016,3 +3018,104 @@ maybe_remove_unused_call_args (struct function *fn, gimple *stmt) update_stmt_fn (fn, stmt); } } + +#if CHECKING_P + +namespace { + +class gimple_test : public ::selftest::test +{ + protected: + void + verify_gimple_pp (const char *expected, gimple *stmt) + { + pretty_printer pp; + pp_gimple_stmt_1 (&pp, stmt, 0 /* spc */, 0 /* flags */); + EXPECT_STREQ (expected, pp_formatted_text (&pp)); + } +}; + +TEST_F (gimple_test, assign_single) +{ + /* Build "tmp = 5;" */ + 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); + + EXPECT_TRUE (is_gimple_assign (stmt)); + EXPECT_EQ (lhs, gimple_assign_lhs (stmt)); + EXPECT_EQ (lhs, gimple_get_lhs (stmt)); + EXPECT_EQ (rhs, gimple_assign_rhs1 (stmt)); + EXPECT_EQ (NULL, gimple_assign_rhs2 (stmt)); + EXPECT_EQ (NULL, gimple_assign_rhs3 (stmt)); + EXPECT_TRUE (gimple_assign_single_p (stmt)); + EXPECT_EQ (INTEGER_CST, gimple_assign_rhs_code (stmt)); +} + +TEST_F (gimple_test, assign_binop) +{ + /* Build "tmp = a * b;" */ + 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); + + EXPECT_TRUE (is_gimple_assign (stmt)); + EXPECT_EQ (lhs, gimple_assign_lhs (stmt)); + EXPECT_EQ (lhs, gimple_get_lhs (stmt)); + EXPECT_EQ (a, gimple_assign_rhs1 (stmt)); + EXPECT_EQ (b, gimple_assign_rhs2 (stmt)); + EXPECT_EQ (NULL, gimple_assign_rhs3 (stmt)); + EXPECT_FALSE (gimple_assign_single_p (stmt)); + EXPECT_EQ (MULT_EXPR, gimple_assign_rhs_code (stmt)); +} + +TEST_F (gimple_test, nop_stmt) +{ + gimple *stmt = gimple_build_nop (); + verify_gimple_pp ("GIMPLE_NOP", stmt); + EXPECT_EQ (GIMPLE_NOP, gimple_code (stmt)); + EXPECT_EQ (NULL, gimple_get_lhs (stmt)); + EXPECT_FALSE (gimple_assign_single_p (stmt)); +} + +TEST_F (gimple_test, return_stmt) +{ + /* Build "return 7;" */ + tree type = integer_type_node; + tree val = build_int_cst (type, 7); + greturn *stmt = gimple_build_return (val); + verify_gimple_pp ("return 7;", stmt); + + EXPECT_EQ (GIMPLE_RETURN, gimple_code (stmt)); + EXPECT_EQ (NULL, gimple_get_lhs (stmt)); + EXPECT_EQ (val, gimple_return_retval (stmt)); + EXPECT_FALSE (gimple_assign_single_p (stmt)); +} + +TEST_F (gimple_test, return_without_value) +{ + greturn *stmt = gimple_build_return (NULL); + verify_gimple_pp ("return;", stmt); + + EXPECT_EQ (GIMPLE_RETURN, gimple_code (stmt)); + EXPECT_EQ (NULL, gimple_get_lhs (stmt)); + EXPECT_EQ (NULL, gimple_return_retval (stmt)); + EXPECT_FALSE (gimple_assign_single_p (stmt)); +} + +} /* anon namespace. */ + +#endif /* CHECKING_P */ -- 1.8.5.3