From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 93823 invoked by alias); 21 Nov 2017 23:27: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 93791 invoked by uid 89); 21 Nov 2017 23:27:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.7 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KB_WAM_FROM_NAME_SINGLEWORD,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=00am, 00AM, restrictive 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; Tue, 21 Nov 2017 23:27:28 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4ADD74A6EA; Tue, 21 Nov 2017 23:27:27 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-247.ams2.redhat.com [10.36.116.247]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B272A5D960; Tue, 21 Nov 2017 23:27:26 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id vALNROVR021896; Wed, 22 Nov 2017 00:27:24 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id vALNRKkc017070; Wed, 22 Nov 2017 00:27:20 +0100 Date: Wed, 22 Nov 2017 00:27:00 -0000 From: Jakub Jelinek To: Martin =?utf-8?B?TGnFoWth?= Cc: Jeff Law , gcc-patches@gcc.gnu.org Subject: [PATCH] Fix i?86 bootstrap (PR rtl-optimization/82044) Message-ID: <20171121232720.GD14653@tucnak> Reply-To: Jakub Jelinek References: <20170920081519.GU1701@tucnak> <7cff6742-bd7a-5ea2-80fb-aca74610f591@suse.cz> <7e976ae2-4aab-9abd-1990-94b9804db8f9@redhat.com> <87d09716-916c-974f-9a4e-7fa95f6b97c3@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87d09716-916c-974f-9a4e-7fa95f6b97c3@suse.cz> User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes X-SW-Source: 2017-11/txt/msg01959.txt.bz2 Hi! On Wed, Nov 15, 2017 at 08:31:00AM +0100, Martin Liška wrote: > On 11/08/2017 05:31 PM, Jeff Law wrote: > > I don't see an updated patch in this thread? THe last message I see is > > this one where you indicate you're going to tweak the patch and re-test. > > > > Jeff > > Yes, I tweaked and tested following patch. > > Martin > >From a369ac78b887e219a375e17d6817c1f744e71779 Mon Sep 17 00:00:00 2001 > From: marxin > Date: Thu, 19 Oct 2017 13:38:01 +0200 > Subject: [PATCH] Fix UBSAN errors in dse.c (PR rtl-optimization/82044). > > gcc/ChangeLog: > > 2017-10-19 Martin Liska > > PR rtl-optimization/82044 > PR tree-optimization/82042 > * dse.c (check_mem_read_rtx): Check for overflow. Unfortunately this patch broke i686-linux bootstrap, during stage2 libgcc configure fails due to numerous ICEs. There are 2 problems with the patch: 1) if the mode of the read is BLKmode, then width is set to -1, so offset > HOST_WIDE_INT_MAX - width invokes UB at compile time and is true for any offset > HOST_WIDE_INT_MIN if the compiler wraps the result around. 2) clear_rhs_from_active_local_stores () is the punt action in record_store, but not in check_mem_read_rtx, where e.g. a few lines above it if canon_address fails it does add_wild_read instead. The following patch fixes those two issues and adds similar overflow check to record_store too (in that spot width is always non-negative, so we don't need a special width == -1 handling). Bootstrapped successfully on i686-linux, ok for trunk if it passes regtest there (and pending x86_64-linux bootstrap + regtest)? 2017-11-21 Jakub Jelinek PR rtl-optimization/82044 PR tree-optimization/82042 * dse.c (record_store): Check for overflow. (check_mem_read_rtx): Properly check for overflow if width == -1, call add_wild_read instead of clear_rhs_from_active_local_stores on overflow and log it into dump_file. --- gcc/dse.c.jj 2017-11-21 23:18:18.000000000 +0100 +++ gcc/dse.c 2017-11-21 23:28:08.952439915 +0100 @@ -1342,6 +1342,12 @@ record_store (rtx body, bb_info_t bb_inf else width = GET_MODE_SIZE (GET_MODE (mem)); + if (offset > HOST_WIDE_INT_MAX - width) + { + clear_rhs_from_active_local_stores (); + return 0; + } + if (group_id >= 0) { /* In the restrictive case where the base is a constant or the @@ -1981,9 +1987,13 @@ check_mem_read_rtx (rtx *loc, bb_info_t else width = GET_MODE_SIZE (GET_MODE (mem)); - if (offset > HOST_WIDE_INT_MAX - width) + if (width == -1 + ? offset == HOST_WIDE_INT_MIN + : offset > HOST_WIDE_INT_MAX - width) { - clear_rhs_from_active_local_stores (); + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, " adding wild read, due to overflow.\n"); + add_wild_read (bb_info); return; } Jakub