From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 57621 invoked by alias); 3 Jan 2018 16:31:14 -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 57059 invoked by uid 89); 3 Jan 2018 16:31:14 -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_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; Wed, 03 Jan 2018 16:31:13 +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 E9AE14A6FA; Wed, 3 Jan 2018 16:31:11 +0000 (UTC) Received: from redhat.com (ovpn-204-27.brq.redhat.com [10.40.204.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 63A8060F87; Wed, 3 Jan 2018 16:31:10 +0000 (UTC) Date: Wed, 03 Jan 2018 16:31:00 -0000 From: Marek Polacek To: GCC Patches , Jason Merrill , Nathan Sidwell Cc: Richard Sandiford Subject: C++ PATCH to fix ICE with vector expr folding (PR c++/83659) Message-ID: <20180103163107.GF23422@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.1 (2017-09-22) X-SW-Source: 2018-01/txt/msg00152.txt.bz2 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. Bootstrapped/regtested on x86_64-linux, ok for trunk/7? 2018-01-03 Marek Polacek PR c++/83659 * constexpr.c (cxx_fold_indirect_ref): Use unsigned HOST_WIDE_INT when computing offsets. * g++.dg/torture/pr83659.C: New test. diff --git gcc/cp/constexpr.c gcc/cp/constexpr.c index 1aeacd51810..cf7c994b381 100644 --- gcc/cp/constexpr.c +++ gcc/cp/constexpr.c @@ -3109,9 +3109,10 @@ cxx_fold_indirect_ref (location_t loc, tree type, tree op0, bool *empty_base) && (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (op00type)))) { - 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); diff --git gcc/testsuite/g++.dg/torture/pr83659.C gcc/testsuite/g++.dg/torture/pr83659.C index e69de29bb2d..d9f709bb520 100644 --- gcc/testsuite/g++.dg/torture/pr83659.C +++ gcc/testsuite/g++.dg/torture/pr83659.C @@ -0,0 +1,11 @@ +// PR c++/83659 +// { dg-do compile } + +typedef int V __attribute__ ((__vector_size__ (16))); +V a; + +int +main () +{ + reinterpret_cast (&a)[-1] += 1; +} Marek