From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 4E2E93858D37 for ; Thu, 7 Sep 2023 18:32:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4E2E93858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694111576; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HTHglYpAk3z+0wazN79Kl8sCN28gEyzZ35LOF4mor24=; b=Bxo7QUb+Jz2/JfQ0Huc/uueVOekeH/z1PlxP3wRePg+dgml4kvlXf8WceZc/r/D04FpxoW 5AQEBLZZXU9pjPtAPNEOMjPSBsAEUOnDGnsKN6OqsEI4wG6jfa88KgTiYsCP4aZapcZ/0Z 6xFDteBXv4Z2a5vXWjlhfAETFVT2b0A= Received: from mail-oo1-f72.google.com (mail-oo1-f72.google.com [209.85.161.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-400-Q-kWq2F-OZCMGZqpGGeeKA-1; Thu, 07 Sep 2023 14:32:54 -0400 X-MC-Unique: Q-kWq2F-OZCMGZqpGGeeKA-1 Received: by mail-oo1-f72.google.com with SMTP id 006d021491bc7-570c9545f55so1133238eaf.2 for ; Thu, 07 Sep 2023 11:32:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694111573; x=1694716373; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HTHglYpAk3z+0wazN79Kl8sCN28gEyzZ35LOF4mor24=; b=mLeHnzS0dK9EwxhaVPmDwE9ivsz0AuDPj3MgltHE65Xv53e2qDH4EKhY0WYOrX1+Rw WffRER4Va043Pqat0mCtk+0EYG1BY/JKR8kon4kPc4K6FdOfLDn+LMSuCwJNfrwpXZkr LmAQGE49OZ+mGS7EezrDAlF5KfoMcJmmWzhdpRY7dtyonTYqe3cae3dlpqY8U0lXJ+XI HYz9+j0klvqeIQ19ew5n8/10oKDKwDijfvN8Kh/LwItO4R5bViZQnC4pdcEMJ48o7yAV Sxl1gFcjvUoi9vgS2NBMfoKdTe+EjNCJlyv7ONmQpwN3UvOlCb30qiIVU/sS3Wu4AjNp ks+A== X-Gm-Message-State: AOJu0YxASyZlrQmaA1ZFWegyCwpupCqTCdUSAZ/Im17RVE2tU3qbscRc 6I6iEunV296qeFuEB8Ppx+v9I27iRNYK2Gt3Byk9CiZJGb6twcv4Q8QOW0/AZ1FYO2Cjv2x/jX4 rtzsPuhrB0k9Ilvs3yA== X-Received: by 2002:a05:6358:278c:b0:13a:6748:9312 with SMTP id l12-20020a056358278c00b0013a67489312mr241094rwb.19.1694111573564; Thu, 07 Sep 2023 11:32:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHMEurB080yqudDq6mG2aJbDc8s74Eq3osCdzWLoAvhFuNUTr023xxzLbj1EgOR2i+6cp/RPA== X-Received: by 2002:a05:6358:278c:b0:13a:6748:9312 with SMTP id l12-20020a056358278c00b0013a67489312mr241073rwb.19.1694111573213; Thu, 07 Sep 2023 11:32:53 -0700 (PDT) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id i3-20020a0cf483000000b0064f4f14aecesm1977qvm.24.2023.09.07.11.32.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Sep 2023 11:32:52 -0700 (PDT) Message-ID: <0bca25f4-c684-c56d-b919-8ffe2368e376@redhat.com> Date: Thu, 7 Sep 2023 14:32:51 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 Subject: Re: [PATCH v2] c++: Move consteval folding to cp_fold_r To: Marek Polacek Cc: GCC Patches References: <20230901172348.445289-1-polacek@redhat.com> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 9/7/23 11:23, Marek Polacek wrote: > On Tue, Sep 05, 2023 at 04:36:34PM -0400, Jason Merrill wrote: >> On 9/5/23 15:59, Marek Polacek wrote: >>> On Tue, Sep 05, 2023 at 10:52:04AM -0400, Jason Merrill wrote: >>>> On 9/1/23 13:23, Marek Polacek wrote: >>>>> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? >>>>> >>>>> -- >8 -- >>>>> >>>>> In the review of P2564: >>>>> >>>>> it turned out that in order to correctly handle an example in the paper, >>>>> we should stop doing immediate evaluation in build_over_call and >>>>> bot_replace, and instead do it in cp_fold_r. This patch does that. >>>>> >>>>> Another benefit is that this is a pretty significant simplification, at >>>>> least in my opinion. Also, this fixes the c++/110997 ICE (but the test >>>>> doesn't compile yet). >>>>> >>>>> The main drawback seems to be that cp_fold_r doesn't process as much >>>>> code as we did before: uninstantiated templates >>>> >>>> That's acceptable, it's an optional diagnostic. >>>> >>>>> and things like "false ? foo () : 1". >>>> >>>> This is a problem. Maybe we want cp_fold_r to recurse into the arms of a >>>> COND_EXPR before folding them away? Maybe only if we know we've seen an >>>> immediate function? >>> >>> Unfortunately we had already thrown the dead branch away when we got to >>> cp_fold_r. I wonder if we have to adjust cxx_eval_conditional_expression >>> to call cp_fold_r on the dead branch too, >> >> Hmm, I guess so. >> >>> perhaps with a new ff_ flag to skip the whole second switch in cp_fold_r? >> >> Or factor out the immediate function handling to a separate walk function >> that cp_fold_r also calls? > > I did that. > >>> But then it's possible that the in_immediate_context checks have to stay. >> >> We can just not do the walk in immediate (or mce_true) context, like we >> currently avoid calling cp_fold_function. > > Right. Unfortunately I have to check even when mce_true, consider > > consteval int bar (int i) { if (i != 1) throw 1; return 0; } > constexpr int a = 0 ? bar(3) : 3; I disagree; the call is in a manifestly constant-evaluated expression, and so is now considered an immediate function context, and we should accept that example. >> For mce_unknown I guess we'd want >> to set *non_constant_p instead of giving an error. > > I did not do this because I haven't found a case where it would make > a difference. I think it will given the above comment. > diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc > index 0ca4370deab..397d5c7ec3f 100644 > --- a/gcc/cp/constexpr.cc > +++ b/gcc/cp/constexpr.cc > @@ -2311,6 +2311,29 @@ cxx_dynamic_cast_fn_p (tree fndecl) > && CP_DECL_CONTEXT (fndecl) == abi_node); > } > > +/* Return true if we are in the body of a consteval function. > + This is in addition to in_immediate_context because that > + uses current_function_decl which may not be available. CTX is > + the current constexpr context. */ > + > +static bool > +in_immediate_context (const constexpr_ctx *ctx) > +{ > + if (in_immediate_context ()) > + return true; Can't we check for mce_true here instead of looking at the call chain? > +/* A wrapper around cp_fold_immediate_r. */ > + > +void > +cp_fold_immediate (tree *tp) > +{ Maybe return early if consteval isn't supported in the active standard? Jason