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 CC881385828E for ; Fri, 17 Feb 2023 21:27:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CC881385828E 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=1676669249; 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=tXof8Qo2TLZqL03kLXSteD6P0aXgLGteTgW781M+3us=; b=hHFamkamXZUfC5hWHNZpLACOysHO85MhVnuzFKjJ2WCjIXMbDDTSzGha1d+VvI/u6Ag48L oZOxHvycPc+JbG0nvPw2kGqOqGFtRqfBIpAmmA/ymr1WCqaht+2bo9KbATb0F5311eawZJ pOil7ehWhudAkyxN7g66JqhzHOCNmTM= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-144-i34OSBxGPfODt-OzxT4Dhg-1; Fri, 17 Feb 2023 16:27:28 -0500 X-MC-Unique: i34OSBxGPfODt-OzxT4Dhg-1 Received: by mail-qv1-f72.google.com with SMTP id a10-20020a0cefca000000b0053cd4737a42so1012794qvt.22 for ; Fri, 17 Feb 2023 13:27:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=tXof8Qo2TLZqL03kLXSteD6P0aXgLGteTgW781M+3us=; b=3ECkMYjCx7bILw5+KqEhtF3qz/XikN3CXd0yzq9gGUPmZ/q3GCZKmdyRe6+bhaG7C/ NrB7VHZQfzzI0yqx7FdSvUGYl5IAU63LTHx/4OgjU6YsnDN/9owuHcsoD5AyTJJbg9X3 CdXBRHi8CUH+v0JSmq16Z74ehUQ3prvCMgsoS/jZBUepPxhTkxucRpFWvrdOfYIlPV+b la6jxSzdLWHENAQjUPQ/ghKjSDay6z8exK5hONOQPIzQjmHMKLP2OFs4l85COIQpE9WD kVIkcX6HxLJCVlGC3QJN2NeEhDwX0UQb+/Pf9NSuQFPSeMIvMN6ro+e5k8nsifxP8fXa r4jw== X-Gm-Message-State: AO0yUKVROu3BzUbAIvZfvN/dtQcgba3FYrwr46Abm+BumCv7HlLwhSKs zaJUS20xwP5dL5crlCZ7dSGzB6Xjli6KNO5qFm0WstzS8zc1NtZzV+jxxN6ADQEtZPsoXTrb1ub KgUbt8DyrMrrvQujNBw== X-Received: by 2002:a05:622a:1653:b0:3b6:3a16:a19 with SMTP id y19-20020a05622a165300b003b63a160a19mr4522741qtj.54.1676669247497; Fri, 17 Feb 2023 13:27:27 -0800 (PST) X-Google-Smtp-Source: AK7set+tG2MRIYsn3NtlDvnvbLH+nbDkGjZtWanGheh0e0RAyhUvRlSXdmiUmPTfvVEIwVkCyeDRGQ== X-Received: by 2002:a05:622a:1653:b0:3b6:3a16:a19 with SMTP id y19-20020a05622a165300b003b63a160a19mr4522727qtj.54.1676669247212; Fri, 17 Feb 2023 13:27:27 -0800 (PST) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id z11-20020ac8430b000000b003b9a50c8fa1sm3985730qtm.87.2023.02.17.13.27.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Feb 2023 13:27:26 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Fri, 17 Feb 2023 16:27:25 -0500 (EST) To: Marek Polacek cc: Patrick Palka , Jason Merrill , GCC Patches Subject: Re: [PATCH v2] c++: ICE with redundant capture [PR108829] In-Reply-To: Message-ID: References: <20230217185847.33102-1-polacek@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=-13.9 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_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 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. > } > > tree type = begin_lambda_type (r); > 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 > -- > 2.39.2 > >