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 826BF3858D37 for ; Fri, 3 Mar 2023 16:17:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 826BF3858D37 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=1677860235; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zqx6c7mBwrNsQ7x9Pqq61fKpCh4eOTfwcbRXxjGu/i8=; b=LLcVww1xWbRchUBtudALdzB+YP0DPMDX4x3aBMnWTFgCAUYNUlzRNRX9aGJmXSNyHcVFkr edlbG7DFERvkN5Jrg2mYlJeKKIeNx/60zRG8zQZF6RELXrXm4FhX51Rc79qoYqYb4CwOaY gPahYkKube9tHevGpulfI5HgdyWfr3w= Received: from mail-yw1-f198.google.com (mail-yw1-f198.google.com [209.85.128.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-29-2T5RUVCeOcSA0CexFUhmZg-1; Fri, 03 Mar 2023 11:17:08 -0500 X-MC-Unique: 2T5RUVCeOcSA0CexFUhmZg-1 Received: by mail-yw1-f198.google.com with SMTP id 00721157ae682-536c525d470so28898347b3.18 for ; Fri, 03 Mar 2023 08:17:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677860228; h=content-transfer-encoding:in-reply-to:from:references: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=zqx6c7mBwrNsQ7x9Pqq61fKpCh4eOTfwcbRXxjGu/i8=; b=7EvWcYO38k8ceJj//3TGNJpUTs7urUhcZrXGFZh93BpDLBMI05EsTt6Hq2EC65QYHI nk69x3AntyyUgyHlroBGWKop5BJGWYF+5PZrUs+sUSrfQTqTAdGsxATQ5HErkGeN3GN8 UBpsgZ905cdS1ZKBfSoRHVHMpi3W986mRXPfQ/NcmFqD6jbPSEDkJG3C/fybOTlGLxN2 7Fpy1YPmt49qovKaYu84qWdhKSV66zQs0vOo3uekQxkdp7j2PMR3KpstHXeGCIfyu5Ql RgBWHwvuPn1nn/gVXzx33QGQjT1nRZyekivv8i5ysmARY1FUIFkiJir2PXa9cpaiA0RU ORhA== X-Gm-Message-State: AO0yUKWVpDd53uN+DmXUitz2KcRKt5hqoQNShujyexaiF4RtdSJoRCDS NNSK+ubNNMCEyrZeYAC4ZdBlKibv9s1SfDX4/Oxo8YuNrorjI/5GQpFOBQDlmqhbGgTr6raF97I ZF4EsDanlPlPeEPR1EA== X-Received: by 2002:a05:7508:3791:b0:4c:cd52:8c35 with SMTP id ch17-20020a057508379100b0004ccd528c35mr77190gbb.4.1677860227690; Fri, 03 Mar 2023 08:17:07 -0800 (PST) X-Google-Smtp-Source: AK7set8M/6/HdCGcD8ErYwMbx4yPBdcXfz/L9P2vnv+pBx1zK8GjBShMfsQujs4D7xbrb8bD5kU5jQ== X-Received: by 2002:a05:7508:3791:b0:4c:cd52:8c35 with SMTP id ch17-20020a057508379100b0004ccd528c35mr77186gbb.4.1677860227110; Fri, 03 Mar 2023 08:17:07 -0800 (PST) Received: from [192.168.1.108] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id q28-20020a05620a2a5c00b007422fd3009esm2035662qkp.20.2023.03.03.08.17.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Mar 2023 08:17:06 -0800 (PST) Message-ID: <952a64b0-5680-5bed-751b-1c0374163071@redhat.com> Date: Fri, 3 Mar 2023 11:17:05 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH] c++: thinko in extract_local_specs [PR108998] To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20230303145821.1081489-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20230303145821.1081489-1-ppalka@redhat.com> 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=-12.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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 3/3/23 09:58, Patrick Palka wrote: > In order to fix PR100295, r13-4730-g18499b9f848707 attempted to make > extract_local_specs walk the given pattern twice, ignoring unevaluated > operands the first time around so that we prefer to process a local > specialization in an evaluated context if it appears in one (we process > a local specialization once even if it appears multiple times in the > pattern). > > But there's a thinko in the patch, namely that we don't actually walk > the pattern twice, because we reuse the visited set for the second walk > (to avoid processing a local specialization twice), and the root node > (and any nodes leading up to an unevaluated operand) is considered > visited already. So the patch effectively made extract_local_specs > ignore unevaluated operands altogether, which this testcase demonstrates > isn't quite safe (extract_local_specs never sees 'aa' and we don't save > its local specialization, so we later try to specialize 'aa' on the spot > with the args {{int},{42}} which causes us to nonsensically substitute > its auto with 42.) > > This patch fixes this by walking only the trees we skipped over during > the first walk the second time around. > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk/12? OK. > PR c++/108998 > > gcc/cp/ChangeLog: > > * pt.cc (el_data::skipped_trees): New data member. > (extract_locals_r): Push to skipped_trees any unevaluated > contexts that we skipped over. > (extract_local_specs): During the second walk, consider only > the trees in skipped_trees. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/lambda-generic11.C: New test. > --- > gcc/cp/pt.cc | 10 +++++++++- > gcc/testsuite/g++.dg/cpp2a/lambda-generic11.C | 13 +++++++++++++ > 2 files changed, 22 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-generic11.C > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index ba1b3027513..85136df1730 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -13052,6 +13052,8 @@ public: > tsubst_flags_t complain; > /* True iff we don't want to walk into unevaluated contexts. */ > bool skip_unevaluated_operands = false; > + /* The unevaluated contexts that we avoided walking. */ > + auto_vec skipped_trees; > > el_data (tsubst_flags_t c) > : extra (NULL_TREE), complain (c) {} > @@ -13066,6 +13068,7 @@ extract_locals_r (tree *tp, int *walk_subtrees, void *data_) > if (data.skip_unevaluated_operands > && unevaluated_p (TREE_CODE (*tp))) > { > + data.skipped_trees.safe_push (*tp); > *walk_subtrees = 0; > return NULL_TREE; > } > @@ -13168,8 +13171,13 @@ extract_local_specs (tree pattern, tsubst_flags_t complain) > context). */ > data.skip_unevaluated_operands = true; > cp_walk_tree (&pattern, extract_locals_r, &data, &data.visited); > + /* Now walk the unevaluated contexts we skipped the first time around. */ > data.skip_unevaluated_operands = false; > - cp_walk_tree (&pattern, extract_locals_r, &data, &data.visited); > + for (tree t : data.skipped_trees) > + { > + data.visited.remove (t); > + cp_walk_tree (&t, extract_locals_r, &data, &data.visited); > + } > return data.extra; > } > > diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic11.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic11.C > new file mode 100644 > index 00000000000..418650699e3 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic11.C > @@ -0,0 +1,13 @@ > +// PR c++/108999 > +// { dg-do compile { target c++20 } } > + > +template > +void ice(T a) { > + auto aa = a; > + auto lambda = []() { > + if constexpr (sizeof(aa) + I != 42) {} > + }; > + lambda.template operator()<0>(); > +} > + > +template void ice(int);