From patchwork Mon Oct 26 11:32:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Trippelsdorf X-Patchwork-Id: 535870 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 67E121412FD for ; Mon, 26 Oct 2015 22:32:37 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=p6n2tEMh; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=tHkdI3W9met3tr6jKKwwU9tqOA178CZxtDOU4sk6cemWS24Ccw Q1uS1/L35mcFoPWHIrTat2e7UUxts0Fwu67PJZf4GmRh/ul0vnTdfLs5RXSh+cfS ee1hesjS4p1DwNeQlFUyARaJsBdlwVFR30TVHNsTCvwLSw26Dok+3bwkQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=EGsMy8vyjFDUZCKKdNXkbEWDMOQ=; b=p6n2tEMhXzHtvExWPzFo QnHA72WVvBqe29jW1Dsk4YsTPoHzpePIr+xe1uwtc+rUp/dv2RVcpkEdzWvOqwwL K8UTh9gsX1qJtCp9T8qYAu5IXlCX6/RknhWb+rxLbJlSX2Ym5Ss6Djv4riM1mnwz dauo3XPGDobG9zgQcmOlyYk= Received: (qmail 49686 invoked by alias); 26 Oct 2015 11:32:28 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 49677 invoked by uid 89); 26 Oct 2015 11:32:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.4 required=5.0 tests=AWL, BAYES_00, FROM_12LTRDOM, KAM_MXURI, RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=no version=3.3.2 X-HELO: mail.ud10.udmedia.de Received: from ud10.udmedia.de (HELO mail.ud10.udmedia.de) (194.117.254.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 26 Oct 2015 11:32:26 +0000 Received: (qmail 23192 invoked from network); 26 Oct 2015 12:32:22 +0100 Received: from ip5b41f88a.dynamic.kabel-deutschland.de (HELO x4) (ud10?360p3@91.65.248.138) by mail.ud10.udmedia.de with ESMTPSA (ECDHE-RSA-AES256-SHA encrypted, authenticated); 26 Oct 2015 12:32:22 +0100 Date: Mon, 26 Oct 2015 12:32:22 +0100 From: Markus Trippelsdorf To: gcc-patches@gcc.gnu.org Cc: Jason Merrill Subject: [PATCH] Fix PR68087 Message-ID: <20151026113222.GA418@x4> MIME-Version: 1.0 Content-Disposition: inline Hi, the patch below fixes PR68087, an ICE caused by referring to a negative constexpr array element. Bootstrapped and tested on ppc64le. OK for trunk? gcc-5 also needs a slightly different fix. I'll post that as a follow-up, once this one gets approved. PR c++/68087 * constexpr.c (cxx_eval_array_reference): Guard call to tree_to_shwi(). diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index ebca411b3eb4..0828a90b0e75 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -1782,8 +1782,7 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree t, gcc_unreachable (); } - i = tree_to_shwi (index); - if (i < 0) + if (!tree_fits_shwi_p (index) || tree_to_shwi (index) < 0) { if (!ctx->quiet) error ("negative array subscript"); @@ -1792,6 +1791,7 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree t, } bool found; + i = tree_to_shwi (index); if (TREE_CODE (ary) == CONSTRUCTOR) { HOST_WIDE_INT ix = find_array_ctor_elt (ary, index); diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-array13.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-array13.C new file mode 100644 index 000000000000..ef18a60f3038 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-array13.C @@ -0,0 +1,7 @@ +// PR c++/68087 +// { dg-do compile { target c++11 } } + +constexpr char c[] = "hello"; +constexpr const char *p = c; + +static_assert(*(p - 1) == 'h', ""); // { dg-error "non-constant|negative" }