From patchwork Tue Jan 21 21:39:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1226775 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-517941-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=kyh6+59A; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=T1NgPtP5; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 482MPM4Jnhz9sR8 for ; Wed, 22 Jan 2020 08:39:18 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:content-type :content-transfer-encoding; q=dns; s=default; b=VwlM+F67i0ePDzcq TD13axo9yYrKXXkAWsVVh/kCh4kUoqArUze4e/MzEY99aSjL8SaN2DeY9pXNwBn8 Fptm9LuP7PItz1pZ+62in3WfMfdDzB3i9LJrK1ffuLME4K7yWGx14He43zHNibV9 K/IFyxQQxxY9sW1wuupJqcdXLxk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:content-type :content-transfer-encoding; s=default; bh=ijhoT0kVUgUnoqapGHU+Y6 VeSRM=; b=kyh6+59ALZNQuJlkrl68qm2oU52/d+oRbd2ibutgI0hdfYo7XQd5h4 TFx6XuhRpRVVDusZ77b71eDZBmADfLAlitZ8fcYGky7/qtl07JCgqgxFlSCuZNrt xFKbrSK2ucXVylvPILec+vB9GXGVpNAqPRYNFrLHN2ft8Mee4Bxgg= Received: (qmail 122849 invoked by alias); 21 Jan 2020 21:39:11 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 122841 invoked by uid 89); 21 Jan 2020 21:39:10 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (205.139.110.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 21 Jan 2020 21:39:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579642748; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=OOr9CWNXoW2xmAgI0NNtDxbYZ+R5TnCmhaLfS2mBSNw=; b=T1NgPtP5uTnOCJcmhrNN86EY49Fc6HQuLm5pmMHi08cJuWGKfjIOcp0G0QBBR86cjckZoL dqAhpVq1JYiEe5YxdcGxLz/jBF6RROeAahlboOchZOpTIKkfjMqKubQuvbZ3yEeB8Uq57z i70mHWYM1LTYOterV/hrqgw/VwruZe8= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-214-hl8XoXuwNDqGz0t8xsSDaA-1; Tue, 21 Jan 2020 16:39:05 -0500 Received: by mail-qt1-f200.google.com with SMTP id r9so2931033qtc.4 for ; Tue, 21 Jan 2020 13:39:05 -0800 (PST) Received: from barrymore.redhat.com (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id o6sm17595581qkk.53.2020.01.21.13.39.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jan 2020 13:39:04 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [COMMITTED] PR c++/90732 - ICE with VLA capture and generic lambda. Date: Tue, 21 Jan 2020 16:39:02 -0500 Message-Id: <20200121213902.7505-1-jason@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes We were failing to handle VLA capture in tsubst_lambda_expr; initially building a DECLTYPE_TYPE for the capture and then tsubsting it doesn't give the special VLA handling. So with this patch we call add_capture again for VLAs. Tested x86_64-pc-linux-gnu, applying to trunk. * pt.c (tsubst_lambda_expr): Repeat add_capture for VLAs. --- gcc/cp/pt.c | 37 +++++++++++++++++++----- gcc/testsuite/g++.dg/cpp1y/lambda-vla1.C | 16 ++++++++++ 2 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/lambda-vla1.C base-commit: 8158a4640819dbb3210326e37786fb874f450272 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index cad97514cdc..4520c995028 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -18751,6 +18751,36 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) cap = TREE_CHAIN (cap)) { tree ofield = TREE_PURPOSE (cap); + tree init = TREE_VALUE (cap); + if (PACK_EXPANSION_P (init)) + init = tsubst_pack_expansion (init, args, complain, in_decl); + else + init = tsubst_copy_and_build (init, args, complain, in_decl, + /*fn*/false, /*constexpr*/false); + + if (init == error_mark_node) + return error_mark_node; + + if (init && TREE_CODE (init) == TREE_LIST) + init = build_x_compound_expr_from_list (init, ELK_INIT, complain); + + if (!processing_template_decl + && init && TREE_CODE (init) != TREE_VEC + && variably_modified_type_p (TREE_TYPE (init), NULL_TREE)) + { + /* For a VLA, simply tsubsting the field type won't work, we need to + go through add_capture again. XXX do we want to do this for all + captures? */ + tree name = (get_identifier + (IDENTIFIER_POINTER (DECL_NAME (ofield)) + 2)); + tree ftype = TREE_TYPE (ofield); + bool by_ref = (TYPE_REF_P (ftype) + || (TREE_CODE (ftype) == DECLTYPE_TYPE + && DECLTYPE_FOR_REF_CAPTURE (ftype))); + add_capture (r, name, init, by_ref, !DECL_NORMAL_CAPTURE_P (ofield)); + continue; + } + if (PACK_EXPANSION_P (ofield)) ofield = PACK_EXPANSION_PATTERN (ofield); tree field = tsubst_decl (ofield, args, complain); @@ -18765,13 +18795,6 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) if (field == error_mark_node) return error_mark_node; - tree init = TREE_VALUE (cap); - if (PACK_EXPANSION_P (init)) - init = tsubst_pack_expansion (init, args, complain, in_decl); - else - init = tsubst_copy_and_build (init, args, complain, in_decl, - /*fn*/false, /*constexpr*/false); - if (TREE_CODE (field) == TREE_VEC) { int len = TREE_VEC_LENGTH (field); diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-vla1.C b/gcc/testsuite/g++.dg/cpp1y/lambda-vla1.C new file mode 100644 index 00000000000..c9025c79aa7 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-vla1.C @@ -0,0 +1,16 @@ +// PR c++/90732 +// { dg-do compile { target c++14 } } +// { dg-additional-options "-Wno-vla" } + +/*const*/ int SIZE = 100; + +template +int foo(T t) { + char buf[SIZE] = { 24 }; + return [&buf](auto x){ return buf[x]; }(t); +} + +int main() { + if (foo(0) != 24) + __builtin_abort(); +}