From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 109022 invoked by alias); 20 Sep 2017 07:51:32 -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 73645 invoked by uid 89); 20 Sep 2017 07:50:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No 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,SPF_PASS autolearn=ham version=3.3.2 spammy=reaches, SET 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; Wed, 20 Sep 2017 07:50:35 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 09B58ABAF for ; Wed, 20 Sep 2017 07:50:33 +0000 (UTC) From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Subject: [PATCH] Fix UBSAN errors in dse.c (PR rtl-optimization/82044). To: gcc-patches@gcc.gnu.org Message-ID: Date: Wed, 20 Sep 2017 07:51:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------EE4135033BC68E81F9B04F29" X-IsSubscribed: yes X-SW-Source: 2017-09/txt/msg01322.txt.bz2 This is a multi-part message in MIME format. --------------EE4135033BC68E81F9B04F29 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-length: 546 Hello. Following patch handles UBSAN (overflow) in dce.c. Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. Ready to be installed? Martin gcc/ChangeLog: 2017-09-11 Martin Liska PR rtl-optimization/82044 PR tree-optimization/82042 * dse.c (set_usage_bits): Check properly for a big offset value. (record_store): Do not overflow and set maximum value. (check_mem_read_rtx): Bail out for a big offset. --- gcc/dse.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) --------------EE4135033BC68E81F9B04F29 Content-Type: text/x-patch; name="0001-Fix-UBSAN-errors-in-dse.c-PR-rtl-optimization-82044.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Fix-UBSAN-errors-in-dse.c-PR-rtl-optimization-82044.pat"; filename*1="ch" Content-length: 1263 diff --git a/gcc/dse.c b/gcc/dse.c index cff3ac47356..d519ac70ed5 100644 --- a/gcc/dse.c +++ b/gcc/dse.c @@ -929,7 +929,9 @@ set_usage_bits (group_info *group, HOST_WIDE_INT offset, HOST_WIDE_INT width, { HOST_WIDE_INT i; bool expr_escapes = can_escape (expr); - if (offset > -MAX_OFFSET && offset + width < MAX_OFFSET) + if (offset > -MAX_OFFSET + && offset < MAX_OFFSET + && offset + width < MAX_OFFSET) for (i=offset; igroup_id = group_id; store_info->begin = offset; - store_info->end = offset + width; + if (offset > HOST_WIDE_INT_MAX - width) + store_info->end = HOST_WIDE_INT_MAX; + else + store_info->end = offset + width; + store_info->is_set = GET_CODE (body) == SET; store_info->rhs = rhs; store_info->const_rhs = const_rhs; @@ -1976,6 +1982,14 @@ check_mem_read_rtx (rtx *loc, bb_info_t bb_info) return; } + if (offset > MAX_OFFSET) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, " reaches MAX_OFFSET.\n"); + add_wild_read (bb_info); + return; + } + if (GET_MODE (mem) == BLKmode) width = -1; else --------------EE4135033BC68E81F9B04F29--