From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17343 invoked by alias); 22 Mar 2016 18:52:11 -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 17324 invoked by uid 89); 22 Mar 2016 18:52:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Hx-languages-length:1844, risk 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 22 Mar 2016 18:52:09 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 1BDCA64396; Tue, 22 Mar 2016 18:52:08 +0000 (UTC) Received: from [10.3.113.58] (ovpn-113-58.phx2.redhat.com [10.3.113.58]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2MIq7K4011864; Tue, 22 Mar 2016 14:52:07 -0400 From: Jason Merrill Subject: Re: [PATCH] c++/67376 Comparison with pointer to past-the-end, of array fails inside constant expression To: Jeff Law , Martin Sebor , Gcc Patch List References: <56E72C33.8000301@gmail.com> <56E9B9C3.5000908@redhat.com> <56EB1ECA.90800@gmail.com> <56EC3500.4030701@redhat.com> <56F03567.8040306@redhat.com> <56F07137.1050400@redhat.com> Cc: Marek Polacek , Jakub Jelinek Message-ID: <56F19456.3030900@redhat.com> Date: Tue, 22 Mar 2016 19:10:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <56F07137.1050400@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2016-03/txt/msg01260.txt.bz2 On 03/21/2016 06:09 PM, Jeff Law wrote: > On 03/21/2016 11:54 AM, Jason Merrill wrote: >>>> Both b0 and b1 are invalid and should be diagnosed, but only b1 >>>> is. b1 isn't because because by the time we see its initializer >>>> in constexpr.c it's been transformed into the equivalent of "b1 >>>> = (int*)ps" (though we don't see the cast which would also make >>>> it invalid). >>>> >>>> But if we can avoid these early simplifying transformations and >>>> retain a more faithful representation of the original source then >>>> doing the checking later will likely be simpler and result in >>>> detecting more problems with greater consistency and less effort. >>> Do we know where the folding is happening for this case and is it >>> something we can reasonably defer? ie, is this just a case we missed >>> as part of the deferred folding work and hence should have its own >>> distinct BZ to track? >> >> Yes, why is it already folded? > Let's pull that out into a separate BZ and tackle it for gcc-7. I need to understand the issue before I agree to defer it. It turns out that the problem is with how cp_build_binary_op calls cp_pointer_int_sum and thus the c-common pointer_int_sum, which folds. The POINTER_PLUS_EXPRs thus created have been a source of many issues with constexpr evaluation, since it's impossible to reconstruct the original expression, especially because POINTER_PLUS_EXPR uses an unsigned second operand. Deferring lowering to POINTER_PLUS_EXPR would help a lot. But it would indeed be a significant risk at this point. I think let's defer the fix for c++/60760 (i.e. the nullptr_p bits) until stage 1, when it can be combined with the POINTER_PLUS_EXPR fix, and put the rest of this patch in now. Jason