From patchwork Mon Jul 1 21:09:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1954934 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=F/ZQzzF2; 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 4WCdwk56ZFz1xpN for ; Tue, 2 Jul 2024 07:10:12 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C154D3877021 for ; Mon, 1 Jul 2024 21:10:10 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id 9A953385C6C1 for ; Mon, 1 Jul 2024 21:09:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9A953385C6C1 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 9A953385C6C1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719868191; cv=none; b=ujrlWo8MAGvmZFOFrbgCL6XDGg15OFXotgeSlIVwL4H5CexVm3cFqeQv3b0+7s0VATAaIF6PWY+vWTeCYEMlJOdjdJBbhq11tvR5oj3ro6wG+d1C5Zag1a63eVj5AA7jGfZO5O93cuBM7mP8ucwaosnqamERjWo2z4SU/2EzwPI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719868191; c=relaxed/simple; bh=18/LEf4vG69hZESafltAU4jHEm+qCs6/q161/zVyk/M=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=Q2NMV3nVrt4MVQ/Aek8R23Gu7hmfJKU4tVb6IJH87ZUz4OOpF0uuBDLg6Rx08EU7Fz4XMDHb2t/Rr6EuDgniwRwx0Zj5vnm67yxN9Nbj5tcAEf4KAujMh85dlKbluEuguKN1out7hiPFU/IGWca4o01ecAjYluAVkWkzd+KzhNM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719868189; 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=AQrxDMRPRt76ZxlwBOEPkwbUKQhi0y1n373xKrRt1sQ=; b=F/ZQzzF2kcnh3ZYjN3IVdo8lYNbhQUu8lAT7NnOQZE9QGgGXvyt+cF5r6gG4nsC7fc/IH5 DoQmQyPcFatIUzCZhnw3rQ92NCcm9WhPc41B/Z8wHeXMhkE2ezA5HHSvysbNEifnAQmwGy 0IWB+K4odGScHVrVhLCLtsRP7fIkwYk= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-319-rVH9AKLRPv6mDMIRmBe3NQ-1; Mon, 01 Jul 2024 17:09:47 -0400 X-MC-Unique: rVH9AKLRPv6mDMIRmBe3NQ-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-6b5044e1ed6so33833996d6.0 for ; Mon, 01 Jul 2024 14:09:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719868186; x=1720472986; 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=AQrxDMRPRt76ZxlwBOEPkwbUKQhi0y1n373xKrRt1sQ=; b=RiUdA2p+Wc/d2eedoMx4rYVNV8PjFFNXQKHCbE1I88esFNumRMpyfwyDrf7YoSz2tc HB3IIJJD/MF/dattvmHA4cTU0zCSpTnqOTnyxMCKHFVbevEwcoCygmC7V0cwT1iurlTT qn1ZQ0qJ6kwvnmTXX1c/zbM1Gk/z7fIoAeGXOOwPbEIgtLN6sevF/v4XnA8ERWdOdy+P Vs3Fi9wTD2+2Avb/Yev3Sc+2d/1+15VZyZXC61BKLRqBKkfnZX3Qq1F3BEAS3qI/Bhot btL/D4Rchi2DxttgW+NQeZtjKGvTUhehFS48sjn5hwW9Go9HKs4OjXNvdTeTZ446O/IB nm8g== X-Gm-Message-State: AOJu0Yx2j3MMne0Bl/2H9eUf5SUnvDvmtWMbxF/Z/tBQ6mIKIk+9BL3I U1CxOcLE6SIAjaJNHE9d5mh9s5ByshyCeIa32wvr093FWc6JT2iw9hb63/RPCvLFxq6hHzLNpMS GX7Gz9fLBRk+8UG5lD763+bBjjhrk7OVW4Bx2+5DQVHFHKKShibWTxkA89jkGgfU= X-Received: by 2002:a05:6214:f02:b0:6b2:d5d4:5db6 with SMTP id 6a1803df08f44-6b5b7178159mr73494326d6.55.1719868186170; Mon, 01 Jul 2024 14:09:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGB5Y6B5ZDPt65KomJfd4UffZ46Ajs+liYrxheQZeAg0CwMy3aBu+FNrsIc0V6jxo+wfzajCw== X-Received: by 2002:a05:6214:f02:b0:6b2:d5d4:5db6 with SMTP id 6a1803df08f44-6b5b7178159mr73494186d6.55.1719868185829; Mon, 01 Jul 2024 14:09:45 -0700 (PDT) Received: from redhat.com ([2603:7000:9500:34a5::1db4]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b59e5f35c0sm36964156d6.91.2024.07.01.14.09.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 14:09:45 -0700 (PDT) Date: Mon, 1 Jul 2024 17:09:43 -0400 From: Marek Polacek To: Jason Merrill Cc: GCC Patches Subject: [PATCH v2] c++: ICE with computed gotos [PR115469] Message-ID: References: <20240626220436.496205-1-polacek@redhat.com> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/2.2.12 (2023-09-09) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-12.3 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 On Mon, Jul 01, 2024 at 02:44:56PM -0400, Jason Merrill wrote: > On 6/26/24 6:04 PM, Marek Polacek wrote: > > 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. > > This name doesn't suggest non-static variable to me. Maybe > automatic_var_with...? Sounds good. > While we're at it, we should also avoid complaining about thread-local by > checking decl_storage_duration == dk_auto, since [stmt.dcl]/2 is > specifically about automatic. Done here. 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 (automatic_var_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 | 21 +++++++++++++++++---- gcc/testsuite/g++.dg/ext/label17.C | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/label17.C base-commit: c847dcf94499da62e5a28921b404e6e561645d99 diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 03deb1493a4..d439b04bfa7 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -514,6 +514,21 @@ 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. + See [stmt.dcl]/2. */ + +static bool +automatic_var_with_nontrivial_dtor_p (const_tree t) +{ + if (error_operand_p (t)) + return false; + + return (VAR_P (t) + && !TREE_STATIC (t) + && decl_storage_duration (CONST_CAST_TREE (t)) == dk_auto + && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (t))); +} + /* Update data for defined and undefined labels when leaving a scope. */ int @@ -575,8 +590,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 (automatic_var_with_nontrivial_dtor_p (d)) vec_safe_push (cg, d); } @@ -4003,8 +4017,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 (automatic_var_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; +}