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.129.124]) by sourceware.org (Postfix) with ESMTPS id 454A6385701A for ; Thu, 30 Nov 2023 23:34:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 454A6385701A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 454A6385701A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701387257; cv=none; b=mvwolmjCDDRWGc2/hblrVC1A0lB6HEcTClZDmPqI+MsfwrTgfp9BO9wW4vCd9m2cd8h8P3HBSiLLuwucFXtgpdTKWHQ1ea5pLNw3OLbaq8gdsGOCm5GIEEx4D09kC05e7uO1Wfa95Okw6z+ON8nBiG0WLXODMpqJCcNf90Jbq+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701387257; c=relaxed/simple; bh=hNBbkHcV2vdqGzOJ/0Ey14lvbQl0ZNs3L5k/2d+FDnE=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=G5b76W/hAXgK/MNpDrSiwfbGq3dWKwmyERpNRxZ+fvtYngT1LoR4EfK5PiljiqoBZCI2cD3Rg5Ai1lLOjRiYjB2ucHbLpYjyiGBO8JRL8Sl2XbcnHE0EFyGIm++IWro03XtOSZJHn3/9uiVZ6VIoZpblhyKf4tpGOyoQ1sklJVI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701387254; 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=fjdgduBmsqq9AGpsAq1uMj/VxpMFLZqkF/K0IdRV8ts=; b=fpM5Cc9VF3cX7j2q1c3dGEowJ3/Zfc8VynW1qGpQpH6g6JCJ/ruzt5bBTJclD1bQ3RmXMw TWnOIUVTJaGSAZWXub4cQ6YUxfVxQLWwI5DFTw3AOOJiJPcPhow0JLl2HPFIXFP9qpWtUq XJ2sezzPGBDgzlIBFBx1VHVPdxXFQls= Received: from mail-yw1-f200.google.com (mail-yw1-f200.google.com [209.85.128.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-547-SKxLOrxYNV6-FVv4rKcTMA-1; Thu, 30 Nov 2023 18:34:04 -0500 X-MC-Unique: SKxLOrxYNV6-FVv4rKcTMA-1 Received: by mail-yw1-f200.google.com with SMTP id 00721157ae682-5caf86963ecso22459067b3.3 for ; Thu, 30 Nov 2023 15:34:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701387243; x=1701992043; 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=fjdgduBmsqq9AGpsAq1uMj/VxpMFLZqkF/K0IdRV8ts=; b=l1Sx4dmEcOHq/3aXLQLInXwizxB029lYKn6B5fqJ6s8xeENRkfvNrpLbcskYWFBRuO GJGHUEdtXAv2+M81RQh0qFd7XgRl25+kR797S5wYLes8yI9qKsXIIQMYU49tmB4C2I/i d8uaaXuEJYxtYDtn7j9V3sigPCJr7iwd+JsjozZr8mOEmTPhVbxXVn7JUy71xk0C9/Ww HWSlQnFDwnJsBH4af6OAgCpc9ax8IGwgVgM51UwlJKHX25AOd7Ee9eaujj7BLaU6smfF d5MtYb/Q8dkg6WvRoldqLjn34ufaNlgetCnzhcQxgoNx8iMXLIqk60NgkVgW50G+ukvq gFYw== X-Gm-Message-State: AOJu0YxQtIHZw6SzfQkjKLzDClnsKx6XdtCp+fu9lgdSkoLtVfUZ/CXc ZZ29bCnnOWK86iRWqPJIo1hIUi3TlckNnr5BOdy6ibpalNZ5YDuMu7nqLOHZ5wlYnJjpJioQQPa eLX7U5o0fpjde3TDxew== X-Received: by 2002:a0d:d40f:0:b0:5cc:7431:871 with SMTP id w15-20020a0dd40f000000b005cc74310871mr25804003ywd.25.1701387243735; Thu, 30 Nov 2023 15:34:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IFiEDSe99in9si9AoZCvRaeD/JYxSXG/ngXMNuihqpQMoU8ywNFDumxMctlRyewFskXjGKyhQ== X-Received: by 2002:a0d:d40f:0:b0:5cc:7431:871 with SMTP id w15-20020a0dd40f000000b005cc74310871mr25803981ywd.25.1701387243365; Thu, 30 Nov 2023 15:34:03 -0800 (PST) Received: from [192.168.1.145] (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 x1-20020a0ce241000000b00677f34c4b4fsm927953qvl.6.2023.11.30.15.34.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 30 Nov 2023 15:34:02 -0800 (PST) Message-ID: <1d9a1b66-c1ba-4aa1-80e3-09c5e1840845@redhat.com> Date: Thu, 30 Nov 2023 18:34:01 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5] c++: implement P2564, consteval needs to propagate up [PR107687] To: Marek Polacek Cc: GCC Patches References: <20230823194904.1925591-1-polacek@redhat.com> <974dbde5-e1d8-90dc-a023-df214883403c@redhat.com> <462dd81b-cfb2-4066-bca4-403335147f5d@redhat.com> <6a3303b5-85b3-4d8f-a4e3-4f41455ec6d1@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=-6.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE 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 11/23/23 11:46, Marek Polacek wrote: > v5 greatly simplifies the code. Indeed, it's much cleaner now. > I still need a new ff_ flag to signal that we can return immediately > after seeing an i-e expr. That's still not clear to me: > + /* In turn, maybe promote the function we find ourselves in... */ > + if ((data->flags & ff_find_escalating_expr) > + && DECL_IMMEDIATE_FUNCTION_P (decl) > + /* ...but not if the call to DECL was constant; that is the > + "an immediate invocation that is not a constant expression" > + case. */ > + && (e = cxx_constant_value (stmt, tf_none), e == error_mark_node)) > + { > + /* Since we had to set DECL_ESCALATION_CHECKED_P before the walk, > + we call promote_function_to_consteval directly which doesn't > + check unchecked_immediate_escalating_function_p. */ > + if (current_function_decl) > + promote_function_to_consteval (current_function_decl); > + *walk_subtrees = 0; > + return stmt; > + } This is the one use of ff_find_escalating_expr, and it seems redundant with the code immediately below, where we use complain (derived from ff_mce_false) to decide whether to return immediately. Can we remove this hunk and the flag, and merge find_escalating_expr with cp_fold_immediate? I think you want to walk the function body for three-ish reasons: 1) at EOF, to check for escalation 2) at EOF, to check for errors 3) at error time, to explain escalation It's not clear to me that we need a flag to distinguish between them. When we encounter an immediate-escalating expression E: A) if we're in an immediate-escalating function, escalate and return E (#1, #3). B) otherwise, if we're diagnosing, error and continue (#2). C) otherwise, return E (individual expression mce_unknown walk from constexpr.cc). > @@ -1178,11 +1388,19 @@ cp_fold_r (tree *stmt_p, int *walk_subtrees, void *data_ > ) > *walk_subtrees = 0; > /* Don't return yet, still need the cp_fold below. */ > } > - cp_fold_immediate_r (stmt_p, walk_subtrees, data); > + else > + cp_fold_immediate_r (stmt_p, walk_subtrees, data); > } > > *stmt_p = stmt = cp_fold (*stmt_p, data->flags); > > + /* For certain trees, like +foo(), the cp_fold below will remove the +, s/below/above/? > +/* We've stashed immediate-escalating functions. Now see if they indeed > + ought to be promoted to consteval. */ > + > +void > +process_pending_immediate_escalating_fns () > +{ > + /* This will be null for -fno-immediate-escalation. */ > + if (!deferred_escalating_exprs) > + return; > + > + for (auto e : *deferred_escalating_exprs) > + if (TREE_CODE (e) == FUNCTION_DECL && !DECL_ESCALATION_CHECKED_P (e)) > + cp_fold_immediate (&DECL_SAVED_TREE (e), mce_false, e); > +} > + > +/* We've escalated every function that could have been promoted to > + consteval. Check that we are not taking the address of a consteval > + function. */ > + > +void > +check_immediate_escalating_refs () > +{ > + /* This will be null for -fno-immediate-escalation. */ > + if (!deferred_escalating_exprs) > + return; > + > + for (auto ref : *deferred_escalating_exprs) > + { > + if (TREE_CODE (ref) == FUNCTION_DECL) > + continue; > + tree decl = (TREE_CODE (ref) == PTRMEM_CST > + ? PTRMEM_CST_MEMBER (ref) > + : TREE_OPERAND (ref, 0)); > + if (DECL_IMMEDIATE_FUNCTION_P (decl)) > + taking_address_of_imm_fn_error (ref, decl); > + } > + > + deferred_escalating_exprs = nullptr; > } Could these be merged, so you do a single loop of cp_fold_immediate over function bodies or non-function expressions? I'd expect that to work. Jason