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 0593E385828E for ; Fri, 17 Feb 2023 21:06:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0593E385828E 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=1676667972; 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=4jr53NwjcBPJwUAReLVrBtKOMiSRQ74BaifiFErQKyw=; b=IPmoGZH01Zi2J13EsUtDjhe5eaDhLE/utwvJdScgUojwALuhlT3dUGde9CHgECPa8wmsjz OBSe2oZnvdNvvyehmhOXItgXrs5Vdmif2R0UHHsVsTQcgub9rBzHRfUlk9VLblO8akS6Sh trDsykugMHqZ6nViyhm+pL5roZvfxjo= 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_128_GCM_SHA256) id us-mta-515-JL27pVBfMOuZfn8GF5uVNA-1; Fri, 17 Feb 2023 16:06:11 -0500 X-MC-Unique: JL27pVBfMOuZfn8GF5uVNA-1 Received: by mail-qk1-f200.google.com with SMTP id j19-20020ae9c213000000b00706bf3b459eso514186qkg.11 for ; Fri, 17 Feb 2023 13:06:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4jr53NwjcBPJwUAReLVrBtKOMiSRQ74BaifiFErQKyw=; b=FLSJ6YVVTbkXwjSkXzIQ/ibPx3BqonbZY6hz93soi/wfLz4mgABA5wKE18l0wFTtmQ SPlv+bEkAZHgACGJ/7hxn+YP8i5qTcqj8XmrG1z/LpAFk/D3eu0Wbs7PbKIaqxSt3tAM kDJ6EqYTD6WhS/39ApafizmmaQ6kkf2ZoGEdrvfCL8IP56ZGhWlKNHZoqFv+VEGs1J3i +tk+qrgCx/xDkBJCsjHFGPBEDnPsnsZ0Q9V5z7dJXyWrxMicYOgj94gPhnxwCJRhvjwV ehIhjtzxkO/eiR8C8fNhm0Zv1xvweuB9Ob/q8aBVsU9LCv4pbmR/glr5+YecjukMaq9P E+bg== X-Gm-Message-State: AO0yUKXvP05pAJIsqINgUpv9CqBf9Dr0KZgDCtz6DH1hHqONbdbruqHW L/I8kVIO+RWnQkVKYAB2JvFwECobQfCpflLYmtvwDAZTvuxv3NTHThA5gkM4OU7xrS4X1oWNjSP kTwdHpR4Gz6ILywXjOA== X-Received: by 2002:ac8:5990:0:b0:3bd:1647:9333 with SMTP id e16-20020ac85990000000b003bd16479333mr8872636qte.28.1676667970729; Fri, 17 Feb 2023 13:06:10 -0800 (PST) X-Google-Smtp-Source: AK7set9nAwrBxF7j5cTxYY026d6ai12JCtbTc3evpTE6UE4rKNeCESFwBaCfyzBjs7LP3L3AZIcncg== X-Received: by 2002:ac8:5990:0:b0:3bd:1647:9333 with SMTP id e16-20020ac85990000000b003bd16479333mr8872609qte.28.1676667970437; Fri, 17 Feb 2023 13:06:10 -0800 (PST) Received: from redhat.com (2603-7000-9500-34a5-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:34a5::1db4]) by smtp.gmail.com with ESMTPSA id b8-20020ac812c8000000b003bd21323c80sm632550qtj.11.2023.02.17.13.06.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Feb 2023 13:06:09 -0800 (PST) Date: Fri, 17 Feb 2023 16:06:07 -0500 From: Marek Polacek To: Patrick Palka Cc: Jason Merrill , GCC Patches Subject: [PATCH v2] c++: ICE with redundant capture [PR108829] Message-ID: References: <20230217185847.33102-1-polacek@redhat.com> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/2.2.9 (2022-11-12) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-12.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_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, 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)); } 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