From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 126000 invoked by alias); 10 Jun 2015 15:10:45 -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 125867 invoked by uid 89); 10 Jun 2015 15:10:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 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, 10 Jun 2015 15:10:35 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z2he8-0000E3-8j for gcc-patches@gcc.gnu.org; Wed, 10 Jun 2015 11:10:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59822) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z2he8-0000DF-2O for gcc-patches@gcc.gnu.org; Wed, 10 Jun 2015 11:10:28 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id C88A82CD839 for ; Wed, 10 Jun 2015 15:10:27 +0000 (UTC) Received: from c64.redhat.com (vpn-230-17.phx2.redhat.com [10.3.230.17]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t5AFAMLr007589; Wed, 10 Jun 2015 11:10:27 -0400 From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 07/17] Add test-gimple.c to gcc/unittests Date: Wed, 10 Jun 2015 15:10:00 -0000 Message-Id: <1433949898-22033-8-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1433949898-22033-1-git-send-email-dmalcolm@redhat.com> References: <1433949898-22033-1-git-send-email-dmalcolm@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 X-IsSubscribed: yes X-SW-Source: 2015-06/txt/msg00770.txt.bz2 gcc/unittests/ChangeLog: * test-gimple.c: New file. --- gcc/unittests/test-gimple.c | 179 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 gcc/unittests/test-gimple.c diff --git a/gcc/unittests/test-gimple.c b/gcc/unittests/test-gimple.c new file mode 100644 index 0000000..093f5fb --- /dev/null +++ b/gcc/unittests/test-gimple.c @@ -0,0 +1,179 @@ +/* Unit tests for gimple. + Copyright (C) 2015 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#include + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "tm.h" +#include "opts.h" +#include "signop.h" +#include "hash-set.h" +#include "fixed-value.h" +#include "alias.h" +#include "flags.h" +#include "symtab.h" +#include "tree-core.h" +#include "stor-layout.h" +#include "tree.h" +#include "stringpool.h" +#include "stor-layout.h" +#include "rtl.h" +#include "predict.h" +#include "vec.h" +#include "hashtab.h" +#include "hash-set.h" +#include "machmode.h" +#include "hard-reg-set.h" +#include "input.h" +#include "function.h" +#include "dominance.h" +#include "cfg.h" +#include "cfganal.h" +#include "basic-block.h" +#include "tree-ssa-alias.h" +#include "internal-fn.h" +#include "gimple-fold.h" +#include "gimple-expr.h" +#include "toplev.h" +#include "print-tree.h" +#include "tree-iterator.h" +#include "gimplify.h" +#include "tree-cfg.h" +#include "basic-block.h" +#include "double-int.h" +#include "alias.h" +#include "symtab.h" +#include "wide-int.h" +#include "inchash.h" +#include "tree.h" +#include "fold-const.h" +#include "stor-layout.h" +#include "stmt.h" +#include "hash-table.h" +#include "tree-ssa-alias.h" +#include "internal-fn.h" +#include "gimple-expr.h" +#include "is-a.h" +#include "gimple.h" +#include "tree-pass.h" +#include "context.h" +#include "hash-map.h" +#include "plugin-api.h" +#include "ipa-ref.h" +#include "cgraph.h" +#include "gimple-pretty-print.h" + +namespace { + +class gimple_test : public ::testing::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. */ -- 1.8.5.3