From patchwork Tue Dec 1 17:38:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1408976 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=flLyKsfz; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Clq8c1ZBLz9s1l for ; Wed, 2 Dec 2020 04:38:56 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ED91E3844008; Tue, 1 Dec 2020 17:38:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED91E3844008 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1606844334; bh=4jo1orF4H8TvwC28pln1WIvMMUnKT4Azybs767rjuP8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=flLyKsfzIS/zXJ6yo0akYZ3BJ74SofiOheSDI5BMiV3RjlTBGUTHtk+Boz7eWRnrq XzH+WSgecYCtX+7X1rCCua4lqOntWi8vCikg1JnbmLcp7eeROPkd7uC+nEDgVXGRTS s/XUMBOtKoJDXvSpmPFn0/r3kstdnXQceH8D/eD8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id C40C73857C4F for ; Tue, 1 Dec 2020 17:38:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C40C73857C4F Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-474-Wa-o578OPZWmRnqbio7ldw-1; Tue, 01 Dec 2020 12:38:49 -0500 X-MC-Unique: Wa-o578OPZWmRnqbio7ldw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AFA2E18C89DC for ; Tue, 1 Dec 2020 17:38:48 +0000 (UTC) Received: from pdp-11.redhat.com (ovpn-118-89.rdu2.redhat.com [10.10.118.89]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5719D10016DB; Tue, 1 Dec 2020 17:38:48 +0000 (UTC) To: GCC Patches , Jason Merrill Subject: [PATCH] c++: Fix tsubst ICE with invalid code [PR97993, PR97187] Date: Tue, 1 Dec 2020 12:38:42 -0500 Message-Id: <20201201173842.1908175-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-15.0 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Marek Polacek via Gcc-patches From: Marek Polacek Reply-To: Marek Polacek Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" I had a strong sense of deja vu when looking into this, and no wonder, since this is almost identical to c++/95728. Since r11-423 tsubst_copy_and_build/TREE_LIST uses tsubst_tree_list instead of open coding it. While the latter could return an error node wrapped in a TREE_LIST, the former can return a naked error node. That broke in tsubst_copy_and_build/NEW_EXPR, because we were accessing TREE_VALUE of an error node. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? gcc/cp/ChangeLog: PR c++/97187 PR c++/97993 * pt.c (tsubst_copy_and_build) : Return error_mark_node if init is erroneous. gcc/testsuite/ChangeLog: PR c++/97187 PR c++/97993 * g++.dg/eh/crash2.C: New test. * g++.dg/template/crash132.C: New test. --- gcc/cp/pt.c | 2 ++ gcc/testsuite/g++.dg/eh/crash2.C | 20 ++++++++++++++++++++ gcc/testsuite/g++.dg/template/crash132.C | 6 ++++++ 3 files changed, 28 insertions(+) create mode 100644 gcc/testsuite/g++.dg/eh/crash2.C create mode 100644 gcc/testsuite/g++.dg/template/crash132.C base-commit: b46314c78061a5156bac44a317c87d32b00d4295 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 4fb0bc82c31..72d6cc3ad98 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -19829,6 +19829,8 @@ tsubst_copy_and_build (tree t, parameter packs are of length zero. */ if (init == NULL_TREE && TREE_OPERAND (t, 3) == NULL_TREE) init_vec = NULL; + else if (init == error_mark_node) + RETURN (error_mark_node); else { init_vec = make_tree_vector (); diff --git a/gcc/testsuite/g++.dg/eh/crash2.C b/gcc/testsuite/g++.dg/eh/crash2.C new file mode 100644 index 00000000000..fff8e142fd6 --- /dev/null +++ b/gcc/testsuite/g++.dg/eh/crash2.C @@ -0,0 +1,20 @@ +// PR c++/97187 +// { dg-do compile { target c++14 } } +// { dg-options "-fno-exceptions" } + +auto yp = [] { return 0; }; + +template +DI +zl () +{ + auto au = [] () -> DI { return *new auto (true ? yp : throw); }; // { dg-error "exception handling disabled" } + + return au (); +} + +auto +vd () +{ + return zl (); +} diff --git a/gcc/testsuite/g++.dg/template/crash132.C b/gcc/testsuite/g++.dg/template/crash132.C new file mode 100644 index 00000000000..f6f4863e937 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/crash132.C @@ -0,0 +1,6 @@ +// PR c++/97993 +// { dg-do compile { target c++14 } } + +template T a; +template auto foo (); +struct S decltype (foo ); // { dg-error "" }