From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 42655 invoked by alias); 6 Jan 2019 11:02:30 -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 42632 invoked by uid 89); 6 Jan 2019 11:02:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_SHORT,SPF_PASS autolearn=ham version=3.3.2 spammy=Following, prev, evaluated X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 06 Jan 2019 11:02:27 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 46EFFAF0D; Sun, 6 Jan 2019 11:02:24 +0000 (UTC) To: "gcc-patches@gcc.gnu.org" Cc: Jeff Law , Richard Biener From: Tom de Vries Subject: [RFC] Add gcc_assert_implies Message-ID: Date: Sun, 06 Jan 2019 11:02:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------D8A5D4B23AE39E6FD5E52550" X-IsSubscribed: yes X-SW-Source: 2019-01/txt/msg00238.txt.bz2 This is a multi-part message in MIME format. --------------D8A5D4B23AE39E6FD5E52550 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-length: 38 Hi, Comments welcome. Thanks, - Tom --------------D8A5D4B23AE39E6FD5E52550 Content-Type: text/x-patch; name="0001-RFC-Add-gcc_assert_implies.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="0001-RFC-Add-gcc_assert_implies.patch" Content-length: 2892 [RFC] Add gcc_assert_implies [ Following up on "Fix bug in simplify_ternary_operation" ( https://gcc.gnu.org/ml/gcc-patches/2017-11/msg01699.html ). ] The C/C++ languages do not support the implication logical operator a -> b, so we typically use '!a || b'. Or, possibly the equivalent but more complicated '!(a && !b)'. Both have the convenient property that b is not evaluated if !a. However, for both forms, the more complex and/or long operands a and b become, the harder it becomes to understand that there's an implication relationship. Add a macro gcc_assert_implies(a, b) that allows us to express a top-level implication relationship in an assert. The semantics of gcc_assert_implies (a, b) can understood as: ... if (a) gcc_assert (b); ... [ So an alternative name could be gcc_assert_if, gcc_if_assert or gcc_cond_assert. ] Also, using this kind of assert will make it easier to spot that: ... gcc_assert_implies (a, b); if (a) { ... } ... can be simplified into: ... if (a) { gcc_assert (b); ... } ... 2019-01-06 Tom de Vries * system.h (gcc_assert_implies): Define. * gimple-iterator.c (gsi_insert_seq_nodes_before): Use gcc_assert_implies. * simplify-rtx.c (simplify_const_relational_operation): Same. --- gcc/gimple-iterator.c | 2 +- gcc/simplify-rtx.c | 5 ++--- gcc/system.h | 2 ++ 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/gcc/gimple-iterator.c b/gcc/gimple-iterator.c index e0e4e123678..2e55ec00c0c 100644 --- a/gcc/gimple-iterator.c +++ b/gcc/gimple-iterator.c @@ -119,7 +119,7 @@ gsi_insert_seq_nodes_before (gimple_stmt_iterator *i, basic_block bb; gimple_seq_node cur = i->ptr; - gcc_assert (!cur || cur->prev); + gcc_assert_implies (cur, cur->prev); if ((bb = gsi_bb (*i)) != NULL) update_bb_for_stmts (first, last, bb); diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 748155a5823..eabe6eeb281 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -5234,9 +5234,8 @@ simplify_const_relational_operation (enum rtx_code code, rtx trueop0; rtx trueop1; - gcc_assert (mode != VOIDmode - || (GET_MODE (op0) == VOIDmode - && GET_MODE (op1) == VOIDmode)); + gcc_assert_implies (mode == VOIDmode, + GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode); /* If op0 is a compare, extract the comparison arguments from it. */ if (GET_CODE (op0) == COMPARE && op1 == const0_rtx) diff --git a/gcc/system.h b/gcc/system.h index d04f8fd3360..abbb121a8b4 100644 --- a/gcc/system.h +++ b/gcc/system.h @@ -748,6 +748,8 @@ extern void fancy_abort (const char *, int, const char *) #define gcc_assert(EXPR) ((void)(0 && (EXPR))) #endif +#define gcc_assert_implies(EXPR1, EXPR2) gcc_assert (!(EXPR1) || (EXPR2)) + #if CHECKING_P #define gcc_checking_assert(EXPR) gcc_assert (EXPR) #else --------------D8A5D4B23AE39E6FD5E52550--