From patchwork Wed Jun 26 22:04:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1952797 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Mr13hjNa; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W8bNP169pz20Xg for ; Thu, 27 Jun 2024 08:05:08 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 104C53875450 for ; Wed, 26 Jun 2024 22:05:07 +0000 (GMT) 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 [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 1ABE73875450 for ; Wed, 26 Jun 2024 22:04:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1ABE73875450 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1ABE73875450 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719439487; cv=none; b=YDlP7LdD/oypt0Q1c6PH9yaJItH+uw5zVGCtA772xbts0+KNf6tBHpVo++ks48xSy8QE6vUIiiK/yT+L/BOc5EhBciHaVxMt6i7iMSFpMn/3zUUMr7uqY8RwalpwtC+vWXNhjxpc7pae8r0VKEDwtgrAmZCzguwbrfwP6ypJQHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719439487; c=relaxed/simple; bh=4AQ6kSjcZZO1DYf3wixQq7v//Qn5kMKuN0W8Rx55rO0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ZwDcNF6qYfAh0oRtik9hfrrUbQOqFxSjml28ByqluHgeWyrCnnCgwcfuf1CK5iUcuRBwi4ydKdZYojiyaWTttRjrRa2WXfAhQ/TO+TO+VAO/u7gnvMKPaYVXUFt/ptN3RavUROGhVVIB14v2aZSApC1Ap1QwxAJjdeUISo5tzVk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719439485; 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=wEWL0OKcxYx/vrU42bHG4haVifZuxE6bXS6xY4v7cko=; b=Mr13hjNaOvRinNG01B6R/fprJf4jTsZVpsttItFAECUkSmgt66hM5MUvH8fcbemxtMCtN+ PX9bpfpY+kbZWnMA6aQtL6ZWiaRL0iec7hDx6iKYpTX4+qFhEYRRym9ahFL6hTW8U5fJNv SfNcmEPdX4hRjBkcb7gk+QnxZoEQ5Z4= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-536-yYA8N9a0P_utrJVdM7qDsg-1; Wed, 26 Jun 2024 18:04:43 -0400 X-MC-Unique: yYA8N9a0P_utrJVdM7qDsg-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8869819560AB for ; Wed, 26 Jun 2024 22:04:41 +0000 (UTC) Received: from pdp-11.lan (unknown [10.22.33.16]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 88A2E19560BF; Wed, 26 Jun 2024 22:04:40 +0000 (UTC) From: Marek Polacek To: GCC Patches , Jason Merrill Subject: [PATCH] c++: ICE with computed gotos [PR115469] Date: Wed, 26 Jun 2024 18:04:36 -0400 Message-ID: <20240626220436.496205-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.5 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_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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- This is a low-prio crash on invalid code where we ICE on a VAR_DECL with erroneous type. I thought I'd try to avoid putting such decls into ->names and ->names_in_scope but that sounds riskier than the following cleanup. PR c++/115469 gcc/cp/ChangeLog: * decl.cc (decl_with_nontrivial_dtor_p): New. (poplevel_named_label_1): Use it. (check_goto_1): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/label17.C: New test. --- gcc/cp/decl.cc | 19 +++++++++++++++---- gcc/testsuite/g++.dg/ext/label17.C | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/label17.C base-commit: 0731985920cdeeeb028f03ddb8a7f035565c1594 diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 03deb1493a4..e5696079c28 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -514,6 +514,19 @@ level_for_consteval_if (cp_binding_level *b) && IF_STMT_CONSTEVAL_P (b->this_entity)); } +/* True if T is a non-static VAR_DECL that has a non-trivial destructor. */ + +static bool +decl_with_nontrivial_dtor_p (const_tree t) +{ + if (error_operand_p (t)) + return false; + + return (VAR_P (t) + && !TREE_STATIC (t) + && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (t))); +} + /* Update data for defined and undefined labels when leaving a scope. */ int @@ -575,8 +588,7 @@ poplevel_named_label_1 (named_label_entry **slot, cp_binding_level *bl) if (bl->kind == sk_catch) vec_safe_push (cg, get_identifier ("catch")); for (tree d = use->names_in_scope; d; d = DECL_CHAIN (d)) - if (TREE_CODE (d) == VAR_DECL && !TREE_STATIC (d) - && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (d))) + if (decl_with_nontrivial_dtor_p (d)) vec_safe_push (cg, d); } @@ -4003,8 +4015,7 @@ check_goto_1 (named_label_entry *ent, bool computed) tree end = b == level ? names : NULL_TREE; for (tree d = b->names; d != end; d = DECL_CHAIN (d)) { - if (TREE_CODE (d) == VAR_DECL && !TREE_STATIC (d) - && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (d))) + if (decl_with_nontrivial_dtor_p (d)) { if (!identified) { diff --git a/gcc/testsuite/g++.dg/ext/label17.C b/gcc/testsuite/g++.dg/ext/label17.C new file mode 100644 index 00000000000..076ef1f798e --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/label17.C @@ -0,0 +1,18 @@ +// PR c++/115469 +// { dg-do compile { target indirect_jumps } } +// { dg-options "" } + +void +fn1 () +{ + b = &&c; // { dg-error "not declared|not defined" } + goto *0; +} + +void +fn2 () +{ +c: + b = &&c; // { dg-error "not declared" } + goto *0; +}