From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 41979 invoked by alias); 11 Apr 2017 20:54:17 -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 41953 invoked by uid 89); 11 Apr 2017 20:54:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,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, 11 Apr 2017 20:54:15 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 992575147E; Tue, 11 Apr 2017 20:54:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 992575147E Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jakub@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 992575147E Received: from tucnak.zalov.cz (ovpn-116-29.ams2.redhat.com [10.36.116.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3D69060E3F; Tue, 11 Apr 2017 20:54:15 +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 v3BKsCBb029577; Tue, 11 Apr 2017 22:54:12 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v3BKsA4W029576; Tue, 11 Apr 2017 22:54:10 +0200 Date: Tue, 11 Apr 2017 20:54:00 -0000 From: Jakub Jelinek To: Richard Biener , Jeff Law Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix fold_binary_loc BIT_IOR_EXPR folding (PR sanitizer/80349) Message-ID: <20170411205410.GX1809@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes X-SW-Source: 2017-04/txt/msg00551.txt.bz2 Hi! This is another case where we miss needed folding from argN or their arguments to the expected expression type (type has to be compatible with opN's type, but argN is after STRIP_NOPS). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-04-11 Jakub Jelinek PR sanitizer/80349 * fold-const.c (fold_binary_loc) : Convert arg0's first argument to type. * g++.dg/ubsan/pr80349.C: New test. --- gcc/fold-const.c.jj 2017-04-10 22:27:00.000000000 +0200 +++ gcc/fold-const.c 2017-04-11 20:07:02.459839450 +0200 @@ -9916,12 +9916,12 @@ fold_binary_loc (location_t loc, } if (c3 != c1) - return fold_build2_loc (loc, BIT_IOR_EXPR, type, - fold_build2_loc (loc, BIT_AND_EXPR, type, - TREE_OPERAND (arg0, 0), - wide_int_to_tree (type, - c3)), - arg1); + { + tem = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0)); + tem = fold_build2_loc (loc, BIT_AND_EXPR, type, tem, + wide_int_to_tree (type, c3)); + return fold_build2_loc (loc, BIT_IOR_EXPR, type, tem, arg1); + } } /* See if this can be simplified into a rotate first. If that --- gcc/testsuite/g++.dg/ubsan/pr80349.C.jj 2017-04-11 20:29:10.154344673 +0200 +++ gcc/testsuite/g++.dg/ubsan/pr80349.C 2017-04-11 20:28:38.000000000 +0200 @@ -0,0 +1,11 @@ +// PR sanitizer/80349 +// { dg-do compile } +// { dg-options "-fsanitize=undefined" } + +extern const long long int v; + +void +foo () +{ + (int)((v & 50 | 051UL) << 0) << 0; +} Jakub