From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 48863 invoked by alias); 25 Jan 2018 14:46:13 -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 48852 invoked by uid 89); 25 Jan 2018 14:46:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-6.9 required=5.0 tests=BAYES_00,GIT_PATCH_1,SPF_HELO_PASS,T_RP_MATCHES_RCVD 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; Thu, 25 Jan 2018 14:46:11 +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 96111C0546CF; Thu, 25 Jan 2018 14:46:10 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-22.ams2.redhat.com [10.36.117.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2DB735D977; Thu, 25 Jan 2018 14:46:03 +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 w0PEjxNe012010; Thu, 25 Jan 2018 15:45:59 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w0PEjvJB010676; Thu, 25 Jan 2018 15:45:57 +0100 Date: Thu, 25 Jan 2018 15:10:00 -0000 From: Jakub Jelinek To: Richard Biener Cc: Marek Polacek , GCC Patches , Jason Merrill , Nathan Sidwell , Richard Sandiford Subject: Re: C++ PATCH to fix ICE with vector expr folding (PR c++/83659) Message-ID: <20180125144557.GO2063@tucnak> Reply-To: Jakub Jelinek References: <20180103163107.GF23422@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.1 (2017-09-22) X-IsSubscribed: yes X-SW-Source: 2018-01/txt/msg02088.txt.bz2 On Fri, Jan 05, 2018 at 09:52:36AM +0100, Richard Biener wrote: > On Wed, Jan 3, 2018 at 5:31 PM, Marek Polacek wrote: > > Here we are crashing because cxx_fold_indirect_ref got a POINTER_PLUS_EXPR > > with offset > signed HOST_WIDE_INT and we tried to convert it to sHWI. > > > > The matching code in fold_indirect_ref_1 uses uHWIs so I've followed suit. > > But that code now also uses poly_uint64 and I'm not sure if any of the > > constexpr.c code should use it, too. But this patch fixes the ICE. > > POINTER_PLUS_EXPR offets are to be interpreted as signed (ptrdiff_t) > so using uhwi and then performing an unsigned division is wrong code. > See mem_ref_offset how to deal with this (ugh - poly-ints...). Basically > you have to force the thing to signed. Like just use > > HOST_WIDE_INT offset = TREE_INT_CST_LOW (op01); Does it really matter here though? Any negative offsets there are UB, we should punt on them rather than try to optimize them. As we known op01 is unsigned, if we check that it fits into shwi_p, it means it will be 0 to shwi max and then we can handle it in uhwi too. /* ((foo*)&vectorfoo)[1] => BIT_FIELD_REF */ if (VECTOR_TYPE_P (op00type) && (same_type_ignoring_top_level_qualifiers_p - (type, TREE_TYPE (op00type)))) + (type, TREE_TYPE (op00type))) + && tree_fits_shwi_p (op01)) { - HOST_WIDE_INT offset = tree_to_shwi (op01); + unsigned HOST_WIDE_INT offset = tree_to_uhwi (op01); tree part_width = TYPE_SIZE (type); - unsigned HOST_WIDE_INT part_widthi = tree_to_shwi (part_width)/BITS_PER_UNIT; + unsigned HOST_WIDE_INT part_widthi + = tree_to_uhwi (part_width) / BITS_PER_UNIT; unsigned HOST_WIDE_INT indexi = offset * BITS_PER_UNIT; tree index = bitsize_int (indexi); if (known_lt (offset / part_widthi, TYPE_VECTOR_SUBPARTS (op00type))) return fold_build3_loc (loc, BIT_FIELD_REF, type, op00, part_width, index); } Jakub