From patchwork Fri Dec 22 03:17:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1879499 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=UmFQn9c0; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4SxCDX3BY2z1ydb for ; Fri, 22 Dec 2023 14:18:17 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 66B5038618F5 for ; Fri, 22 Dec 2023 03:18:15 +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 AB5CF3858C5E for ; Fri, 22 Dec 2023 03:18:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AB5CF3858C5E 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 AB5CF3858C5E 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=1703215082; cv=none; b=e/2rblYF/sTVp8dZOib0mZRSwh/6RmLrlLlp65Ryq7YanlocC2qOSWF/JeQwBLSAOU/CQCOP1dznImMDkZaCgVw/QiC6wik++dRQoiHh1pNJLq2oT2c+etP9iJJRf3wE1ge1ZqAOl9jiH9ux8trDuwV/PjudTZhYU2goZC7h9PA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703215082; c=relaxed/simple; bh=rS+TmX7o/4JArzEueM7gWed60OKG+J4VSfQ0fS0bmQI=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=YQNdExbGW+mzbXubW2b0awlzdF8AelLXiwbLiEd5MB8uVNssYU8rX5qmv6dLA/mlddoiHh5rAHNaGvabcUmST68WqS+Stm2HmimecjtPr0Yg7eKlu5TLsTIad3bS8lKh5KZQINPWmFhKRU5JXw34Vu5+xvXSga3jS4iPAe/STKA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703215080; 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: in-reply-to:in-reply-to:references:references; bh=AM1SJzyqchAGtnHUKfj9Xovzs+Js0yG01liEAFZCcp8=; b=UmFQn9c0QOeGPPHn9HAQTMJNQ9JtW55k+lKOZfbtvlNDyVacJQwzacchRaNT+7OezhSp2+ oKyy9XGYsJ86YMXZ/wB4FUVjKYfBWs2bI3IovivKZbkg5BZxLUxo+ZBY73SCzWLESMBxmn adnr1QD0JHThSleLAp31xTYP80c/og4= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-259-PjRRdxUmNLiHgLzxwd1TEQ-1; Thu, 21 Dec 2023 22:17:58 -0500 X-MC-Unique: PjRRdxUmNLiHgLzxwd1TEQ-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-67abf4618a2so24484466d6.0 for ; Thu, 21 Dec 2023 19:17:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703215077; x=1703819877; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AM1SJzyqchAGtnHUKfj9Xovzs+Js0yG01liEAFZCcp8=; b=pCrckneI6DHxNFW4ePl8ulYaAih99i0AFBW/N0WX8p4pmwBooq6M+xjaE0m5Gn460+ rFym9KxaWY6FZkwms4+8HaX5RDSr1861dryB94Rz0OTwJyr58KFgBnSObJZuZn5YprVq Et8WzH3GZ7RoTY+ELBCovvYUCzho4AXbkXVUvlArv4ccHlebnZpPQJKTxts7hSBtsDbf DNzedBeJpd57HNIdeLQ32KR1me/uDoZ6a1Zh2XXxxr6/ZVTGCn9dG7H9iZcYba97of6r lSxVacc6D61nfqsbnDFzKWgMqjscs2Y4+Jar7xXXNG0ZDNQa/p2K2B+D8qMQdHAyEVou zeoQ== X-Gm-Message-State: AOJu0Yz96Dz5WDTWt6PHqApJ1EKWET9K2Eh3oU2lXh+Juc7PZARFhYb1 qu8JYZcT5B0m2uNu/I2jH/URIsBEzcPKA+Tlump262FhPYNpaR+6SowuwROQAIPweIbXtX4YXra VJWncz7Lo4pwyRAXRinfvWLOmfXAOEup/1R6LkKaXp9SEZEO9DxonkyGb9QuFTkCX0M5iMfCOeK FhUYHqTQ== X-Received: by 2002:a05:6214:262d:b0:67f:40c9:8184 with SMTP id gv13-20020a056214262d00b0067f40c98184mr2650112qvb.30.1703215077676; Thu, 21 Dec 2023 19:17:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IEzUFOryEUvFw43DAxkP/6XTCzKVKUZypcOR5d8xMHGMTnNCy2qCulDZ63mI8e0yLGanGJ2kA== X-Received: by 2002:a05:6214:262d:b0:67f:40c9:8184 with SMTP id gv13-20020a056214262d00b0067f40c98184mr2650103qvb.30.1703215077194; Thu, 21 Dec 2023 19:17:57 -0800 (PST) Received: from jason.com (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id h1-20020a0cf8c1000000b0067f07683decsm1068388qvo.99.2023.12.21.19.17.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 19:17:56 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: computed goto from catch block [PR81438] Date: Thu, 21 Dec 2023 22:17:54 -0500 Message-Id: <20231222031754.3556161-1-jason@redhat.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231221020627.3266898-1-jason@redhat.com> References: <20231221020627.3266898-1-jason@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.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, RCVD_IN_SORBS_WEB, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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 Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- As with 37722, we don't clean up the exception object if a computed goto leaves a catch block, but we can warn about that. PR c++/81438 gcc/cp/ChangeLog: * decl.cc (poplevel_named_label_1): Handle leaving catch. (check_previous_goto_1): Likewise. (check_goto_1): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/label15.C: Require indirect_jumps. * g++.dg/ext/label16.C: New test. --- gcc/cp/decl.cc | 42 ++++++++++++++++++++++++------ gcc/testsuite/g++.dg/ext/label15.C | 1 + gcc/testsuite/g++.dg/ext/label16.C | 34 ++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/label16.C base-commit: d26f589e61a178e898d8b247042b487287ffe121 diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index e044bfa6701..6b4d89e7115 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -571,10 +571,14 @@ poplevel_named_label_1 (named_label_entry **slot, cp_binding_level *bl) if (use->binding_level == bl) { if (auto &cg = use->computed_goto) - 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))) - vec_safe_push (cg, d); + { + 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))) + vec_safe_push (cg, d); + } use->binding_level = obl; use->names_in_scope = obl->names; @@ -3820,7 +3824,12 @@ check_previous_goto_1 (tree decl, cp_binding_level* level, tree names, identified = 2; if (complained) for (tree d : computed) - inform (DECL_SOURCE_LOCATION (d), " does not destroy %qD", d); + { + if (DECL_P (d)) + inform (DECL_SOURCE_LOCATION (d), " does not destroy %qD", d); + else if (d == get_identifier ("catch")) + inform (*locus, " does not clean up handled exception"); + } } return !identified; @@ -3963,15 +3972,32 @@ check_goto_1 (named_label_entry *ent, bool computed) auto names = ent->names_in_scope; for (auto b = current_binding_level; ; b = b->level_chain) { + if (b->kind == sk_catch) + { + if (!identified) + { + complained + = identify_goto (decl, DECL_SOURCE_LOCATION (decl), + &input_location, DK_ERROR, computed); + identified = 2; + } + if (complained) + inform (input_location, + " does not clean up handled exception"); + } 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))) { - complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl), - &input_location, DK_ERROR, - computed); + if (!identified) + { + complained + = identify_goto (decl, DECL_SOURCE_LOCATION (decl), + &input_location, DK_ERROR, computed); + identified = 2; + } if (complained) inform (DECL_SOURCE_LOCATION (d), " does not destroy %qD", d); diff --git a/gcc/testsuite/g++.dg/ext/label15.C b/gcc/testsuite/g++.dg/ext/label15.C index f9d6a0dd626..5a23895d52d 100644 --- a/gcc/testsuite/g++.dg/ext/label15.C +++ b/gcc/testsuite/g++.dg/ext/label15.C @@ -1,4 +1,5 @@ // PR c++/37722 +// { dg-do compile { target indirect_jumps } } // { dg-options "" } extern "C" int printf (const char *, ...); diff --git a/gcc/testsuite/g++.dg/ext/label16.C b/gcc/testsuite/g++.dg/ext/label16.C new file mode 100644 index 00000000000..ea79b6ef1fc --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/label16.C @@ -0,0 +1,34 @@ +// PR c++/81438 +// { dg-do compile { target indirect_jumps } } +// { dg-options "" } + +bool b; +int main() +{ + try + { + try { throw 3; } + catch(...) { + h:; // { dg-warning "jump to label" } + try { throw 7; } + catch(...) { + if (b) + goto *&&h; // { dg-message "computed goto" } + // { dg-message "handled exception" "" { target *-*-* } .-1 } + else + goto *&&g; // { dg-message "computed goto" } + // { dg-message "handled exception" "" { target *-*-* } .-1 } + } + g:; // { dg-warning "jump to label" } + throw; + } + } + catch(int v) + { + __builtin_printf("%d\n", v); + if(v != 3) // 7 because we don't clean up the catch on + __builtin_abort(); // computed goto + } + + return 0; +}