From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 67619 invoked by alias); 25 Apr 2017 16:09:36 -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 67526 invoked by uid 89); 25 Apr 2017 16:09:29 -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,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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, 25 Apr 2017 16:09:28 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EEDFD70723 for ; Tue, 25 Apr 2017 16:09:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EEDFD70723 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jakub@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com EEDFD70723 Received: from tucnak.zalov.cz (ovpn-116-29.ams2.redhat.com [10.36.116.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 844798246A; Tue, 25 Apr 2017 16:09:23 +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 v3PG9LKX011980; Tue, 25 Apr 2017 18:09:21 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v3PG9KON011979; Tue, 25 Apr 2017 18:09:20 +0200 Date: Tue, 25 Apr 2017 16:13:00 -0000 From: Jakub Jelinek To: Marek Polacek Cc: GCC Patches Subject: Re: [PATCH] Fix fold_binary_loc BIT_IOR_EXPR folding (PR sanitizer/80349) Message-ID: <20170425160920.GF1809@tucnak> Reply-To: Jakub Jelinek References: <20170425160525.GU4255@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170425160525.GU4255@redhat.com> User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes X-SW-Source: 2017-04/txt/msg01229.txt.bz2 On Tue, Apr 25, 2017 at 06:05:25PM +0200, Marek Polacek wrote: > Here we are crashing because fold_binary_loc produced a BIT_IOR_EXPR with > incompatible operands. Fixed by adding the missing conversion, similarly > to . > > Bootstrapped/regtested on x86_64-linux, ok for trunk? And 7.1? > > 2017-04-25 Marek Polacek > > PR sanitizer/80349 > * fold-const.c (fold_binary_loc) : Convert arg0's > first argument to type. > > * g++.dg/ubsan/pr80349-2.C: New test. > > diff --git gcc/fold-const.c gcc/fold-const.c > index f0b8e7a..ce4b2df 100644 > --- gcc/fold-const.c > +++ gcc/fold-const.c > @@ -9898,8 +9898,10 @@ fold_binary_loc (location_t loc, > > /* If (C1|C2) == ~0 then (X&C1)|C2 becomes X|C2. */ > if (msk.and_not (c1 | c2) == 0) > - return fold_build2_loc (loc, BIT_IOR_EXPR, type, > - TREE_OPERAND (arg0, 0), arg1); > + { > + tem = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0)); > + return fold_build2_loc (loc, BIT_IOR_EXPR, type, tem, arg1); Shouldn't this use op1 instead of arg1, just in case op1 is a NOP_EXPR of INTEGER_CST or similar unfolded tree? Jakub