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 ADCD5385828E for ; Fri, 17 Feb 2023 18:58:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ADCD5385828E 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=1676660332; 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; bh=gGZg728VYks9imJY1MwXx+ne+pGAydRUFOP6hnmpp0U=; b=FQSD3xCQq0SBWhywmeRBy1LdEFWXVpNWSlaVgphnkSdwbfIqo6JMyRCRXBq7bfI4FogWD5 sEA7pZREdzrVNo3RC4PtQYL9AvrzsMu5EwjoIR4SzgZfeR/Z8smjSrDpo1NjAey6X0JtzF rXob/GUZ6gJyOSZyB7VfDrNgn0aNJoc= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-348-dmm1dzC2P5iLj6p156Br2Q-1; Fri, 17 Feb 2023 13:58:51 -0500 X-MC-Unique: dmm1dzC2P5iLj6p156Br2Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DCC8F1C04B7C for ; Fri, 17 Feb 2023 18:58:50 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.17.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id C14314024BDC; Fri, 17 Feb 2023 18:58:50 +0000 (UTC) From: Marek Polacek To: Jason Merrill , GCC Patches Subject: [PATCH] c++: ICE with redundant capture [PR108829] Date: Fri, 17 Feb 2023 13:58:47 -0500 Message-Id: <20230217185847.33102-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.4 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: 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. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/12? PR c++/108829 gcc/cp/ChangeLog: * lambda.cc (var_to_maybe_prune): Strip location wrappers before checking for a capture proxy. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/lambda/lambda-108829.C: New test. --- gcc/cp/lambda.cc | 1 + gcc/testsuite/g++.dg/cpp0x/lambda/lambda-108829.C | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-108829.C diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc index c752622816d..a12b9c183c2 100644 --- a/gcc/cp/lambda.cc +++ b/gcc/cp/lambda.cc @@ -1700,6 +1700,7 @@ var_to_maybe_prune (tree cap) return NULL_TREE; tree init = TREE_VALUE (cap); + STRIP_ANY_LOCATION_WRAPPER (init); if (is_normal_capture_proxy (init)) init = DECL_CAPTURED_VARIABLE (init); if (decl_constant_var_p (init)) 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: 6245441e124846d0c3551f312d2feef598fe251c -- 2.39.2