From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 127726 invoked by alias); 26 Apr 2016 22:51:47 -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 127713 invoked by uid 89); 26 Apr 2016 22:51:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=20160427, 2016-04-27, Hx-languages-length:2384, H*MI:sk:2016042 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 26 Apr 2016 22:51:45 +0000 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 A52213B759; Tue, 26 Apr 2016 22:51:44 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-113-135.phx2.redhat.com [10.3.113.135]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3QMpg45009244 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 26 Apr 2016 18:51:44 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id u3QMpeqs029546; Wed, 27 Apr 2016 00:51:41 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id u3QMpdm2029545; Wed, 27 Apr 2016 00:51:39 +0200 Date: Tue, 26 Apr 2016 22:51:00 -0000 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] operand_equal_p checking (PR sanitizer/70683) Message-ID: <20160426225139.GZ26501@tucnak.zalov.cz> Reply-To: Jakub Jelinek References: <20160426130238.GU26501@tucnak.zalov.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160426130238.GU26501@tucnak.zalov.cz> User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes X-SW-Source: 2016-04/txt/msg01562.txt.bz2 On Tue, Apr 26, 2016 at 03:02:38PM +0200, Jakub Jelinek wrote: > The debugging hack is too ugly and slows down the compiler (by artificially > increasing number of collisions), so it is not appropriate, but perhaps we > can add some internal only use OEP_* flag, pass it to the recursive calls > of operand_equal_p and if not set and flag_checking, verify > iterative_hash_expr equality in the outermost call). Here is the corresponding checking patch. It uncovered two further issues in the tree.[ch] patch which I'm going to post momentarily. Both patches together bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2016-04-27 Jakub Jelinek PR sanitizer/70683 * tree-core.h (enum operand_equal_flag): Add OEP_NO_HASH_CHECK. * fold-const.c (operand_equal_p): If flag_checking and OEP_NO_HASH_CHECK is not set in flag, recurse with OEP_NO_HASH_CHECK and if it returns non-zero, assert iterative_hash_expr on both args is the same. --- gcc/tree-core.h.jj 2016-04-22 18:21:55.000000000 +0200 +++ gcc/tree-core.h 2016-04-26 17:47:19.875753297 +0200 @@ -765,7 +765,9 @@ enum operand_equal_flag { OEP_ONLY_CONST = 1, OEP_PURE_SAME = 2, OEP_MATCH_SIDE_EFFECTS = 4, - OEP_ADDRESS_OF = 8 + OEP_ADDRESS_OF = 8, + /* Internal within operand_equal_p: */ + OEP_NO_HASH_CHECK = 16 }; /* Enum and arrays used for tree allocation stats. --- gcc/fold-const.c.jj 2016-04-22 18:21:32.000000000 +0200 +++ gcc/fold-const.c 2016-04-26 18:30:40.919080701 +0200 @@ -2749,6 +2749,25 @@ combine_comparisons (location_t loc, int operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags) { + /* When checking, verify at the outermost operand_equal_p call that + if operand_equal_p returns non-zero then ARG0 and ARG1 has the same + hash value. */ + if (flag_checking && !(flags & OEP_NO_HASH_CHECK)) + { + if (operand_equal_p (arg0, arg1, flags | OEP_NO_HASH_CHECK)) + { + inchash::hash hstate0 (0), hstate1 (0); + inchash::add_expr (arg0, hstate0, flags); + inchash::add_expr (arg1, hstate1, flags); + hashval_t h0 = hstate0.end (); + hashval_t h1 = hstate1.end (); + gcc_assert (h0 == h1); + return 1; + } + else + return 0; + } + /* If either is ERROR_MARK, they aren't equal. */ if (TREE_CODE (arg0) == ERROR_MARK || TREE_CODE (arg1) == ERROR_MARK || TREE_TYPE (arg0) == error_mark_node Jakub