From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 90B4E38493E5 for ; Mon, 20 Feb 2023 09:45:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 90B4E38493E5 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=redhat.com Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pTwAr-0005B8-I1 for gcc-patches@gcc.gnu.org; Sun, 19 Feb 2023 21:45:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676861102; 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=tEn3WzWiVE8EBq6cJCKC2YUr0GlFDa8RJ7VnEht3wws=; b=Wro0rtqnkJ/6RILDLJo8EjJX3RlCONbHpGOZ9nOKj0M3qknZz98oPEti/oaUSH+wYEgSRm 8NT9iGslorTvy08pKOo4NuM7G3fqdZpj6/3RfkNdlAjEuUdyfVLqeuuCZzDMQL5tMMcymb 5AbJaTXDRcdRIjDdB7R+451tYX9Kqmo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676861104; 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=tEn3WzWiVE8EBq6cJCKC2YUr0GlFDa8RJ7VnEht3wws=; b=Gq40KPXYV82JpUZDhxD15iP9RIsrPIXI6c+LeqB2qtwfi+0iTLmC1XzKCjW31OULlYMqym 3P7cy8uwUOWQRQzJ5/BMNn/wpz92q53QakUB35LztYAGWGS8XhBsJ36CR/IA1/C8pznwXm SkZ8c/JJgetpAIcGZp4sg+4W/voamOc= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-468-7GBwg3-6PRKDXFavQTv5HA-1; Sun, 19 Feb 2023 21:43:17 -0500 X-MC-Unique: 7GBwg3-6PRKDXFavQTv5HA-1 Received: by mail-qk1-f197.google.com with SMTP id oq35-20020a05620a612300b006fb713618b8so429451qkn.0 for ; Sun, 19 Feb 2023 18:43:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=tEn3WzWiVE8EBq6cJCKC2YUr0GlFDa8RJ7VnEht3wws=; b=o/FPb7N026g6dSk8yvaTXJepsNLktaAVGymxxgRjBLGhkClj6zI9LMUhWxDpjFqOZ5 KO0e0vnwhqcX8Ser43hw3CYv3BBXI8XhqYw//jdWZYiTNmqZImgZqcujmsr6A4PM8Mja QswDZQQvbc2+UIwl8hxQMoGDUnOfj4yT/diNPz+au0/QeL7zUyfUwJlHXYDFX7HREi45 08F8fuDL11dBr/7th2ABeSgxcYG/u9GlrUHRxXkNTnM6Qs3AtJy3JcT9rSdGGKxnohfa QlthxY/XJAscwQ72/a2Z1cwqUZ2ZcUEsEtfH+zQNTHQ+NfkGsKHVZ+RemIpXCxkyhnDQ itCg== X-Gm-Message-State: AO0yUKWdtvtCY8dJYijx5pwQJqUcpDkry1GVn0npk1iEAnIWu69nuu1x L6qOJYst5uIsCKASfgBVMYfNGvy8xSVJNWfB7veTo4OZaKp5qD1N+VvWv4vgGct75ZSXWdh7FUF 4cyfxvHOmJFLSKvrx3A== X-Received: by 2002:ac8:5914:0:b0:3b9:c352:640e with SMTP id 20-20020ac85914000000b003b9c352640emr13324532qty.46.1676860996528; Sun, 19 Feb 2023 18:43:16 -0800 (PST) X-Google-Smtp-Source: AK7set+fuoDEgOSPFVlX9Jxs+AN8EXaAxiE1XinzX0MTF++U4NJE8LEEoR/gGwLsk3PzgDvJ6cBTcw== X-Received: by 2002:ac8:5914:0:b0:3b9:c352:640e with SMTP id 20-20020ac85914000000b003b9c352640emr13324496qty.46.1676860996083; Sun, 19 Feb 2023 18:43:16 -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 p26-20020ac8409a000000b003bb822b0f35sm8167882qtl.71.2023.02.19.18.43.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 19 Feb 2023 18:43:15 -0800 (PST) Message-ID: <564761f4-e31a-2e40-a8c5-ac75d67cdd3b@redhat.com> Date: Sun, 19 Feb 2023 21:43:13 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: Re: [PATCH v3] c++: ICE with redundant capture [PR108829] To: Marek Polacek , Patrick Palka Cc: GCC Patches References: <20230217185847.33102-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 Received-SPF: pass client-ip=170.10.129.124; envelope-from=jason@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9,DKIMWL_WL_HIGH=-0.001,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DKIM_VALID_EF=-0.1,NICE_REPLY_A=-0.09,RCVD_IN_DNSWL_NONE=-0.0001,RCVD_IN_MSPIKE_H2=-0.001,SPF_HELO_NONE=0.001,SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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,SPF_HELO_PASS,SPF_NONE,TXREP autolearn=unavailable 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 2/17/23 14:42, Marek Polacek wrote: > On Fri, Feb 17, 2023 at 04:32:50PM -0500, Patrick Palka wrote: >> On Fri, 17 Feb 2023, Patrick Palka wrote: >> >>> On Fri, 17 Feb 2023, Marek Polacek wrote: >>> >>>> On Fri, Feb 17, 2023 at 03:00:39PM -0500, Patrick Palka wrote: >>>>> On Fri, 17 Feb 2023, Marek Polacek via Gcc-patches wrote: >>>>> >>>>>> Here we crash in is_capture_proxy: >>>>>> >>>>>> /* Location wrappers should be stripped or otherwise handled by the >>>>>> caller before using this predicate. */ >>>>>> gcc_checking_assert (!location_wrapper_p (decl)); >>>>>> >>>>>> so fixed as the comment suggests. We only crash with the redundant >>>>>> capture: >>>>>> >>>>>> int abyPage = [=, abyPage] { ... } >>>>>> >>>>>> because prune_lambda_captures is only called when there was a default >>>>>> capture, and with [=] only abyPage won't be in LAMBDA_EXPR_CAPTURE_LIST. >>>>> >>>>> It's weird that we even get this far in var_to_maybe_prune. Shouldn't >>>>> LAMBDA_CAPTURE_EXPLICIT_P be true for abyPage? >>>> >>>> Ug, I was seduced by the ostensible obviousness and failed to notice >>>> that check. In that light, the correct fix ought to be this. Thanks! >>>> >>>> Bootstrap/regtest running on x86_64-pc-linux-gnu, ok for trunk if it >>>> passes? >>>> >>>> -- >8 -- >>>> Here we crash in is_capture_proxy: >>>> >>>> /* Location wrappers should be stripped or otherwise handled by the >>>> caller before using this predicate. */ >>>> gcc_checking_assert (!location_wrapper_p (decl)); >>>> >>>> We only crash with the redundant capture: >>>> >>>> int abyPage = [=, abyPage] { ... } >>>> >>>> because prune_lambda_captures is only called when there was a default >>>> capture, and with [=] only abyPage won't be in LAMBDA_EXPR_CAPTURE_LIST. >>>> >>>> The problem is that LAMBDA_CAPTURE_EXPLICIT_P wasn't propagated >>>> correctly and so var_to_maybe_prune proceeded where it shouldn't. >>>> >>>> PR c++/108829 >>>> >>>> gcc/cp/ChangeLog: >>>> >>>> * pt.cc (tsubst_lambda_expr): Propagate LAMBDA_CAPTURE_EXPLICIT_P. >>>> >>>> gcc/testsuite/ChangeLog: >>>> >>>> * g++.dg/cpp0x/lambda/lambda-108829.C: New test. >>>> --- >>>> gcc/cp/pt.cc | 4 ++++ >>>> gcc/testsuite/g++.dg/cpp0x/lambda/lambda-108829.C | 11 +++++++++++ >>>> 2 files changed, 15 insertions(+) >>>> create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-108829.C >>>> >>>> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc >>>> index b1ac7d4beb4..f747ce877b5 100644 >>>> --- a/gcc/cp/pt.cc >>>> +++ b/gcc/cp/pt.cc >>>> @@ -19992,6 +19992,10 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) >>>> if (id_equal (DECL_NAME (field), "__this")) >>>> LAMBDA_EXPR_THIS_CAPTURE (r) = field; >>>> } >>>> + >>>> + if (LAMBDA_EXPR_CAPTURE_LIST (r)) >>>> + LAMBDA_CAPTURE_EXPLICIT_P (LAMBDA_EXPR_CAPTURE_LIST (r)) >>>> + = LAMBDA_CAPTURE_EXPLICIT_P (LAMBDA_EXPR_CAPTURE_LIST (t)); >>> >>> I'm not sure how the flag works for pack captures but it looks like >>> this would only propagate the flag to the last expanded capture if >>> the capture was originally a pack. >> >> Testcase: >> >> template >> void f(Ts... ts) { >> constexpr int IDX_PAGE_SIZE = 4096; >> int abyPage = [=, ts...] { return IDX_PAGE_SIZE; }(); >> } >> void h() { >> f<1>(0, 1); >> } > > Thanks a lot for the testacase. Revised patch below. Look OK? > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? OK. > -- >8 -- > Here we crash in is_capture_proxy: > > /* Location wrappers should be stripped or otherwise handled by the > caller before using this predicate. */ > gcc_checking_assert (!location_wrapper_p (decl)); > > We only crash with the redundant capture: > > int abyPage = [=, abyPage] { ... } > > because prune_lambda_captures is only called when there was a default > capture, and with [=] only abyPage won't be in LAMBDA_EXPR_CAPTURE_LIST. > > The problem is that LAMBDA_CAPTURE_EXPLICIT_P wasn't propagated > correctly and so var_to_maybe_prune proceeded where it shouldn't. > > PR c++/108829 > > gcc/cp/ChangeLog: > > * pt.cc (prepend_one_capture): Set LAMBDA_CAPTURE_EXPLICIT_P. > (tsubst_lambda_expr): Pass LAMBDA_CAPTURE_EXPLICIT_P to > prepend_one_capture. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp0x/lambda/lambda-108829-2.C: New test. > * g++.dg/cpp0x/lambda/lambda-108829.C: New test. > > Co-Authored by: Patrick Palka > --- > gcc/cp/pt.cc | 9 ++++++--- > gcc/testsuite/g++.dg/cpp0x/lambda/lambda-108829-2.C | 11 +++++++++++ > gcc/testsuite/g++.dg/cpp0x/lambda/lambda-108829.C | 11 +++++++++++ > 3 files changed, 28 insertions(+), 3 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-108829-2.C > create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-108829.C > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index b1ac7d4beb4..1a071e95004 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -19870,10 +19870,11 @@ tsubst_non_call_postfix_expression (tree t, tree args, > > /* Subroutine of tsubst_lambda_expr: add the FIELD/INIT capture pair to the > LAMBDA_EXPR_CAPTURE_LIST passed in LIST. Do deduction for a previously > - dependent init-capture. */ > + dependent init-capture. EXPLICIT_P is true if the original list had > + explicit captures. */ > > static void > -prepend_one_capture (tree field, tree init, tree &list, > +prepend_one_capture (tree field, tree init, tree &list, bool explicit_p, > tsubst_flags_t complain) > { > if (tree auto_node = type_uses_auto (TREE_TYPE (field))) > @@ -19893,6 +19894,7 @@ prepend_one_capture (tree field, tree init, tree &list, > cp_apply_type_quals_to_decl (cp_type_quals (type), field); > } > list = tree_cons (field, init, list); > + LAMBDA_CAPTURE_EXPLICIT_P (list) = explicit_p; > } > > /* T is a LAMBDA_EXPR. Generate a new LAMBDA_EXPR for the current > @@ -19982,12 +19984,13 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) > prepend_one_capture (TREE_VEC_ELT (field, i), > TREE_VEC_ELT (init, i), > LAMBDA_EXPR_CAPTURE_LIST (r), > + LAMBDA_CAPTURE_EXPLICIT_P (cap), > complain); > } > else > { > prepend_one_capture (field, init, LAMBDA_EXPR_CAPTURE_LIST (r), > - complain); > + LAMBDA_CAPTURE_EXPLICIT_P (cap), complain); > > if (id_equal (DECL_NAME (field), "__this")) > LAMBDA_EXPR_THIS_CAPTURE (r) = field; > diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-108829-2.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-108829-2.C > new file mode 100644 > index 00000000000..4e24470514d > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-108829-2.C > @@ -0,0 +1,11 @@ > +// PR c++/108829 > +// { dg-do compile { target c++11 } } > + > +template > +void f(Ts... ts) { > + constexpr int IDX_PAGE_SIZE = 4096; > + int abyPage = [=, ts...] { return IDX_PAGE_SIZE; }(); // { dg-error "redundant" } > +} > +void h() { > + f<1>(0, 1); > +} > diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-108829.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-108829.C > new file mode 100644 > index 00000000000..e621a0d14d0 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-108829.C > @@ -0,0 +1,11 @@ > +// PR c++/108829 > +// { dg-do compile { target c++11 } } > + > +template > +void f(void) { > + constexpr int IDX_PAGE_SIZE = 4096; > + int abyPage = [=, abyPage] { return IDX_PAGE_SIZE; }(); // { dg-error "redundant" } > +} > +void h() { > + f<1>(); > +} > > base-commit: 5fea1be820508e1fbc610d1a54b61c1add33c36f