From patchwork Fri Dec 2 20:24:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 702092 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tVlCP1nj4z9t2n for ; Sat, 3 Dec 2016 06:51:28 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="uCzwVL2m"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=MblzuY5ESeeE+KpYV79TN1dSjohGR1P4lwpMgehOCKgYYB4QhNafG 5qISoJaH0HIcmh+EJ/i50zXoTKyCCvRYOZg9LIR4dmHMlhjGzCJd6S3AMPkFZiEQ DH/U0Tvs9vDEW/65XwdwOMVzG4xScY6+AEPZxTri6MUwBluEbDp3Kk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=xkd2hvL3RC0t/4/mt6+jhqq3rKQ=; b=uCzwVL2md3C9cQmztOnB dL1BP4pDBs8gdSEQpYqDmvHWtOU3YP+xZSeWHvHRvv5tJJY3s3txiXPPOXCllVVT hyVWDVkVpM1cTDsc6rj6bZwEUq5/0NXF48TjHEwF7BOHF767IvLcgndJ/PyUiR6M gmVsq/OoFUMqx8TMY2LZs+s= Received: (qmail 28323 invoked by alias); 2 Dec 2016 19:51:19 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 28301 invoked by uid 89); 2 Dec 2016 19:51:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=H*m:37724 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Dec 2016 19:51:17 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (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 810C13F20A for ; Fri, 2 Dec 2016 19:51:16 +0000 (UTC) Received: from c64.redhat.com (vpn-227-177.phx2.redhat.com [10.3.227.177]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uB2JpFuZ025497; Fri, 2 Dec 2016 14:51:15 -0500 From: David Malcolm To: Bernd Schmidt , gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH] Add ASSERT_RTX_PTR_EQ Date: Fri, 2 Dec 2016 15:24:04 -0500 Message-Id: <1480710244-37724-1-git-send-email-dmalcolm@redhat.com> In-Reply-To: References: X-IsSubscribed: yes On Fri, 2016-12-02 at 16:28 +0100, Bernd Schmidt wrote: > On 12/01/2016 10:43 PM, David Malcolm wrote: > > > > + rtx_insn *jump_insn = get_insn_by_uid (1); > > > > + ASSERT_EQ (JUMP_INSN, GET_CODE (jump_insn)); > > > > + ASSERT_EQ (ret_rtx, JUMP_LABEL (jump_insn)); > > > > + // FIXME: ^^^ use ASSERT_RTX_PTR_EQ here ^^^ > > > > > > Why is this a fixme and not just done that way (several > > > instances)? > > > > ASSERT_RTX_PTR_EQ doesn't exist yet; there was some discussion > > about it > > in earlier versions of the patch, but I haven't written it. It > > would > > be equivalent to ASSERT_EQ, checking pointer equality, but would > > dump > > the mismatching expected vs actual rtx on failure. > > > > Should I convert this to a TODO, or go ahead and implement > > ASSERT_RTX_PTR_EQ? > > Missed this question. Just add ASSERT_RTX_PTR_EQ, that shouldn't be > hard, should it? > > > Bernd This patch implements an ASSERT_RTX_PTR_EQ macro, like ASSERT_EQ, but which dumps both rtx to stderr if the assertion fails. gcc/ChangeLog: * selftest-rtl.c (selftest::assert_rtx_ptr_eq_at): New function. * selftest-rtl.h (ASSERT_RTX_PTR_EQ): New macro. --- gcc/selftest-rtl.c | 23 +++++++++++++++++++++++ gcc/selftest-rtl.h | 18 ++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/gcc/selftest-rtl.c b/gcc/selftest-rtl.c index 20e6550..c14db43 100644 --- a/gcc/selftest-rtl.c +++ b/gcc/selftest-rtl.c @@ -36,6 +36,29 @@ along with GCC; see the file COPYING3. If not see namespace selftest { +/* Compare rtx EXPECTED and ACTUAL by pointer equality, calling + ::selftest::pass if they are equal, aborting if they are non-equal. + LOC is the effective location of the assertion, MSG describes it. */ + +void +assert_rtx_ptr_eq_at (const location &loc, const char *msg, + rtx expected, rtx actual) +{ + if (expected == actual) + ::selftest::pass (loc, msg); + else + { + fprintf (stderr, "%s:%i: %s: FAIL: %s\n", loc.m_file, loc.m_line, + loc.m_function, msg); + fprintf (stderr, " expected (at %p): ", (void *)expected); + print_rtl (stderr, expected); + fprintf (stderr, "\n actual (at %p): ", (void *)actual); + print_rtl (stderr, actual); + fprintf (stderr, "\n"); + abort (); + } +} + /* Constructor for selftest::rtl_dump_test. Read a dumped RTL function from PATH. Takes ownership of PATH, freeing in dtor. diff --git a/gcc/selftest-rtl.h b/gcc/selftest-rtl.h index 35d6437..cb2772d 100644 --- a/gcc/selftest-rtl.h +++ b/gcc/selftest-rtl.h @@ -47,6 +47,24 @@ assert_rtl_dump_eq (const location &loc, const char *expected_dump, rtx x, assert_rtl_dump_eq (SELFTEST_LOCATION, (EXPECTED_DUMP), (RTX), \ (REUSE_MANAGER)) +/* Evaluate rtx EXPECTED and ACTUAL and compare them with == + (i.e. pointer equality), calling ::selftest::pass if they are + equal, aborting if they are non-equal. */ + +#define ASSERT_RTX_PTR_EQ(EXPECTED, ACTUAL) \ + SELFTEST_BEGIN_STMT \ + const char *desc = "ASSERT_RTX_PTR_EQ (" #EXPECTED ", " #ACTUAL ")"; \ + ::selftest::assert_rtx_ptr_eq_at (SELFTEST_LOCATION, desc, (EXPECTED), \ + (ACTUAL)); \ + SELFTEST_END_STMT + +/* Compare rtx EXPECTED and ACTUAL by pointer equality, calling + ::selftest::pass if they are equal, aborting if they are non-equal. + LOC is the effective location of the assertion, MSG describes it. */ + +extern void assert_rtx_ptr_eq_at (const location &loc, const char *msg, + rtx expected, rtx actual); + /* A class for testing RTL function dumps. */ class rtl_dump_test