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 67930384AB63 for ; Wed, 10 Apr 2024 21:39:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 67930384AB63 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 67930384AB63 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=1712785154; cv=none; b=jGs15QPEZqglgPvNmn13GHRY3kHUPaePiNVLGdZncOeT8i8+bxdu3EWskVBKBSd1KYryuHxHpOh6ySh/P7Xcj1FQ2L+YIR6tBSB8JL0WISZ0DUQuOGEQ8ZWwtzS9LiIf9HNq/u5Oobqlq2wWOyUi5A3nZHEltGfEKfx7VX6drOA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712785154; c=relaxed/simple; bh=IlcpZnZak2qJmJMSTxXI2h0rApP4qBdxc8pxJgmbntg=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=ilSUCIrUaXTd5n4w4CveA0IZcIp7wOXV1Sb2kO12j2lou7QYKIzI5XD1/BQEw9QAXiik3QkpaiNyyTgS9mgmVLeMkXNtqHofrUKyX8E6WcQ6/t7vJ3jo+6rRWXJzg7+6PfbdIo5/kRuztoXtIVLmsKsHffGktyyDUwrvU3RUvzI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712785144; 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: in-reply-to:in-reply-to:references:references; bh=DaF7ZrgD2JIGYhT4I5xr6dgPUlPXaGBieQ2ear4WfI8=; b=hDUScOPXYcqtOyLk/EpBD/CNlJMP/7AG3Su4KsqGC/Wk7he+haVN15Gr8xBEv8FT0oEg4h +e/hmp7vtgruSUs3N1dgCxkDnMM0qTEgCCqf/OSrwMTYlKuRDqTKYhrx7fcmgdB0WtyYF+ 20Myzl/MuaGyeHAYJEY6rBF6w5fwG3s= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-301-aUhZxQZHMki7G662ygu1mA-1; Wed, 10 Apr 2024 17:39:02 -0400 X-MC-Unique: aUhZxQZHMki7G662ygu1mA-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-78a452ee0fbso728055885a.2 for ; Wed, 10 Apr 2024 14:39:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712785142; x=1713389942; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DaF7ZrgD2JIGYhT4I5xr6dgPUlPXaGBieQ2ear4WfI8=; b=JH0VPG7K8R148QHXLFnf3rkcd+6mb2l8vT8BAMNL7CbWDVmBOZu/4SuNjrQesEXGYd H7tp4fHsAf4I50eQKdQZbXNcueyNvcvwYQSBtow5a0q/ZMEX78Tghj06k8z6WL0esF3K F0nDmlt+gH+M3GTA9ze++iNQJTgAI7me8UNSRdtl1N0tMkxe0ex9ulpWJsFrEFykcguV p75h3CbHxeAyEKy7dEpHw0+MMwiIsygApM0GVKI20KEBFTaGOYTrCzdwdh6+u8/xJxh/ hKZ/geOu2xkzK7ATqW0dzDMDZ6wseTOreKMPUmSyZ1HBDomROmjGc3qXFQBfEC7mPyTb gCdw== X-Forwarded-Encrypted: i=1; AJvYcCWOqKnRST+31Rwd7rMNGQ6l67KtcTqAg1mP/TJOtd7to/tmKWzkmhjSS099KtLbrdQDovhXfCg+tJIgRHgfWTMZ1FJIUMj9MQ== X-Gm-Message-State: AOJu0Yz0okqX7Zc4x/V2IzVv7uhOEuBV2/fFqoeR4elzctccqCpbX4Gn qCwZ8/X1KDkdivrV9+jH3cgkGSkiPBS75GTWyU0czubtY9Oadw039+y0jcH+kbvAvPcPKMAj6Lv 0eEOjBrjU5THoSQemwTfdu1Z/LB7uhmMH/LVCJ5ENqnPT+cFPc3F9+WE= X-Received: by 2002:a05:620a:1212:b0:78d:6b00:4f9a with SMTP id u18-20020a05620a121200b0078d6b004f9amr3992460qkj.37.1712785142069; Wed, 10 Apr 2024 14:39:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFkSi3+kdYx66CY81MDK/Bn6dBLaQIVD6mIbMrJyfxbMul7CHxJUu69CEOWNa2JBXBNqy4fcA== X-Received: by 2002:a05:620a:1212:b0:78d:6b00:4f9a with SMTP id u18-20020a05620a121200b0078d6b004f9amr3992449qkj.37.1712785141702; Wed, 10 Apr 2024 14:39:01 -0700 (PDT) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id c42-20020a05620a26aa00b0078d70336243sm104297qkp.49.2024.04.10.14.39.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 14:39:01 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Wed, 10 Apr 2024 17:39:00 -0400 (EDT) To: Jason Merrill cc: Patrick Palka , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c++: recalculating local specs via build_extra_args [PR114303] In-Reply-To: <58bba01c-7d9f-488a-9043-a56c9958a5e8@redhat.com> Message-ID: <77c2d252-8081-0824-d373-cce95265c028@idea> References: <20240311165307.3930810-1-ppalka@redhat.com> <431c6cc1-c2f4-9f9a-9fbc-22781f17d17e@idea> <05f1c2d6-6f32-fecc-12d7-ea62e1da5f2a@idea> <58bba01c-7d9f-488a-9043-a56c9958a5e8@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-14.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,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 Wed, 10 Apr 2024, Jason Merrill wrote: > On 3/12/24 10:51, Patrick Palka wrote: > > On Tue, 12 Mar 2024, Patrick Palka wrote: > > > On Tue, 12 Mar 2024, Jason Merrill wrote: > > > > On 3/11/24 12:53, Patrick Palka wrote: > > > > > > > > > > r13-6452-g341e6cd8d603a3 made build_extra_args walk evaluated contexts > > > > > first so that we prefer processing a local specialization in an > > > > > evaluated > > > > > context even if its first use is in an unevaluated context. But this > > > > > means we need to avoid walking a tree that already has extra > > > > > args/specs > > > > > saved because the list of saved specs appears to be an evaluated > > > > > context. It seems then that we should be calculating the saved specs > > > > > from scratch each time, rather than potentially walking the saved > > > > > specs > > > > > list from an earlier partial instantiation when calling > > > > > build_extra_args > > > > > a second time around. > > > > > > > > Makes sense, but I wonder if we want to approach that by avoiding > > > > walking into > > > > *_EXTRA_ARGS in extract_locals_r? Or do we still want to walk into any > > > > nested > > > > extra args? And if so, will we run into this same problem then? > > > > > > I'm not sure totally but I'd expect a nested extra-args tree to always > > > have empty *_EXTRA_ARGS since the outer extra-args tree should intercept > > > any substitution before the inner extra-args tree can see it? > > > > ... and so in extract_locals_r I think we can assume *_EXTRA_ARGS is > > empty, and not have to explicitly avoid walking it. > > It seems more robust to me to handle _EXTRA_ARGS appropriately in > build_extra_args rather than expect callers to know that they shouldn't pass > in a tree with _EXTRA_ARGS set. At least check and abort in that case? Sounds good. That IMHO seems simpler than actually avoiding walking into *_EXTRA_ARGS from extract_locals_r because we'd have to repeat the walking logic from cp_walk_subtree modulo the *_EXTRA_ARGS walk. How does the following look? Bootstraped and regtested on x86_64-pc-linux-gnu. -- > 8-- Subject: [PATCH] c++: build_extra_args recapturing local specs [PR114303] PR c++/114303 gcc/cp/ChangeLog: * constraint.cc (tsubst_requires_expr): Clear REQUIRES_EXPR_EXTRA_ARGS before calling build_extra_args. * pt.cc (extract_locals_r): Assert *_EXTRA_ARGS is empty. (tsubst_stmt) : Call build_extra_args on the new IF_STMT instead of t which might already have IF_STMT_EXTRA_ARGS. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/constexpr-if-lambda6.C: New test. --- gcc/cp/constraint.cc | 1 + gcc/cp/pt.cc | 16 +++++++++++++++- .../g++.dg/cpp1z/constexpr-if-lambda6.C | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/constexpr-if-lambda6.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 49de3211d4c..8a3b5d80ba7 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -2362,6 +2362,7 @@ tsubst_requires_expr (tree t, tree args, sat_info info) matching or dguide constraint rewriting), in which case we need to partially substitute. */ t = copy_node (t); + REQUIRES_EXPR_EXTRA_ARGS (t) = NULL_TREE; REQUIRES_EXPR_EXTRA_ARGS (t) = build_extra_args (t, args, info.complain); return t; } diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index c38594cd862..6cc9b95fc06 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -13310,6 +13310,19 @@ extract_locals_r (tree *tp, int *walk_subtrees, void *data_) /* Remember local typedefs (85214). */ tp = &TYPE_NAME (*tp); + if (has_extra_args_mechanism_p (*tp)) + { + if (PACK_EXPANSION_P (*tp)) + gcc_checking_assert (!PACK_EXPANSION_EXTRA_ARGS (*tp)); + else if (TREE_CODE (*tp) == REQUIRES_EXPR) + gcc_checking_assert (!REQUIRES_EXPR_EXTRA_ARGS (*tp)); + else if (TREE_CODE (*tp) == IF_STMT + && IF_STMT_CONSTEXPR_P (*tp)) + gcc_checking_assert (!IF_STMT_EXTRA_ARGS (*tp)); + else + gcc_unreachable (); + } + if (TREE_CODE (*tp) == DECL_EXPR) { tree decl = DECL_EXPR_DECL (*tp); @@ -18738,7 +18751,8 @@ tsubst_stmt (tree t, tree args, tsubst_flags_t complain, tree in_decl) IF_COND (stmt) = IF_COND (t); THEN_CLAUSE (stmt) = THEN_CLAUSE (t); ELSE_CLAUSE (stmt) = ELSE_CLAUSE (t); - IF_STMT_EXTRA_ARGS (stmt) = build_extra_args (t, args, complain); + IF_SCOPE (stmt) = NULL_TREE; + IF_STMT_EXTRA_ARGS (stmt) = build_extra_args (stmt, args, complain); add_stmt (stmt); break; } diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if-lambda6.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if-lambda6.C new file mode 100644 index 00000000000..038c2a41210 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if-lambda6.C @@ -0,0 +1,16 @@ +// PR c++/114303 +// { dg-do compile { target c++17 } } + +struct A { static constexpr bool value = true; }; + +int main() { + [](auto x1) { + return [&](auto) { + return [&](auto x3) { + if constexpr (decltype(x3)::value) { + static_assert(decltype(x1)::value); + } + }(A{}); + }(0); + }(A{}); +} -- 2.44.0.548.g91ec36f2cc