From patchwork Wed Aug 21 08:28:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 1974695 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=chy3BPsi; 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 4Wpfcp2cGLz1ydn for ; Wed, 21 Aug 2024 18:28:58 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D6769385EC20 for ; Wed, 21 Aug 2024 08:28:55 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by sourceware.org (Postfix) with ESMTPS id D8CB43858D28 for ; Wed, 21 Aug 2024 08:28:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D8CB43858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D8CB43858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::233 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724228914; cv=none; b=eQ8eBMH4udOQFU0cVcfV6VUjkSzg/2BMbRy1JK6IxxjStVm/QPNp5kTWR4HmaH9cZ9SLelgrx87y+0/1c7v8oDbdVKSK3jezr32jPYvVRjgzUd7At5SmM69ehMqLe5xPLDiDV+qOkDQDfDCShjyv23lgD8/FxmXDs02pTjqf5DA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724228914; c=relaxed/simple; bh=PM6LO1ZMxs/BQwtaWPlT+qRhjJnLPRHbvb1IXPw/cDM=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=v8AWwIG/0c8TxoconJKv47Mtb99EqqD1A9sOtS6sVNdfAaTQHBceLfWF2xPJo6KtdvHvScCen0alUBrNb8bL458QEEhhRIHXie/zubOm69A8IHmIfg3By3H1yGVz6WjL6HhtbxLs6xhLwh/2YhtFLVMB8hwN12Uv48VJB4le+/k= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2f3e071eb64so43565051fa.1 for ; Wed, 21 Aug 2024 01:28:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724228911; x=1724833711; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:to:from:from:to:cc:subject:date:message-id:reply-to; bh=i6a9esfinGhvxI8U/Y1Uy0sUh0ICM9W6x+n0ZoUNvhA=; b=chy3BPsiodGRQRrhicgPL6hVxob6iSe71ftoK8+ycUFR3vXRC35r4YYBZj4kWIIvVv Wp0p/9IkS7olJkhI/qYFi1I6w3pjoFamk/0iSAKVXiM6Z+BPvH6twmSln07Sv9h0Y+Rq Unv5yLw5zQ6t6oklBJCNUiNOjIICnEw0mR7pb31uGHA/hoBD2BUw6Zah0POGrVk/vUlN d4sJA8/lCRcro60ksoiNZcW+HkyionxT6r9p11lu4L0urz+vz+QIYG8ke8kWZdg+yK1r 5NSLSwhU0eEpMv4XMIAnTE9Seu5C90ZHzwx3mtfwirCXqQv4mdRbPLYD910MjrptPPIm OZxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724228911; x=1724833711; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=i6a9esfinGhvxI8U/Y1Uy0sUh0ICM9W6x+n0ZoUNvhA=; b=hy1r84FuKhE1PX9HB4nx6liARtalTB0oe8+XY/Z2xfIN/lLI2knXXeZtjengHVwjhp 8kzSMVlQ3s8RbNdKkZuG8GwAKEPF8kb++YGQ/97pcu1XQLUrNwB33YqWtuMEurbINnLv l5JueGezGXt6q4RENG+3/7YcE5mRQwIrO0Hb/3h54jvQTgluCEDxxGkVfzsVrDRt7xgW jbUm9PpL2REt2gfo4HOK/mktHDufAopTqZEEZFFqpq0ekoKiXFPP0KQkf9W7ro+4clBD ZIXZvAzJNqSvfjbC0l0StTfKryb6nS2I+xV9yXVFRhLo/t0wyvlPKxT0fT4GKwf90xBk eZlw== X-Gm-Message-State: AOJu0YzVGrN8hqW/L7e7BAKA10JZWETL91bfR4goZAoThTQnlxM+TFdR 9QJayYgB0sbt0ul1isMqLFBLXn6bH97Uieb3mqnLN2h1nB5jKaEW1zsglZ7n X-Google-Smtp-Source: AGHT+IGbCl7rUR6Fyxmco8nPa2STMWb3nUqFYCyRvjhSXobNJgZtBpOr0TgHU+OI6Xp8aEYGFiIZxw== X-Received: by 2002:a2e:712:0:b0:2f1:750d:53a7 with SMTP id 38308e7fff4ca-2f3f87ec72emr8741311fa.8.1724228910190; Wed, 21 Aug 2024 01:28:30 -0700 (PDT) Received: from localhost.localdomain (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a838396e0edsm863401066b.222.2024.08.21.01.28.29 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 21 Aug 2024 01:28:29 -0700 (PDT) From: Iain Sandoe X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [pushed] c++, coroutines: Check for malformed functions before splitting. Date: Wed, 21 Aug 2024 09:28:28 +0100 Message-Id: <20240821082828.62860-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.39.2 (Apple Git-143) MIME-Version: 1.0 X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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: , Reply-To: iain@sandoe.co.uk Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org tested on x86_64-darwin, powerpc64-linux and against cppcoro and folly coroutines tests, pushed to trunk as obvious, thanks, Iain --- 8< --- This performs the same basic check that is done by finish_function to catch cases where the function is so badly malformed that we do not have a consistent binding level. gcc/cp/ChangeLog: * coroutines.cc (split_coroutine_body_from_ramp): Check that the binding level is as expected before attempting to outline the function body. Signed-off-by: Iain Sandoe --- gcc/cp/coroutines.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index f7791cbfb9a..7af2a188561 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -4553,10 +4553,16 @@ coro_rewrite_function_body (location_t fn_start, tree fnbody, tree orig, static tree split_coroutine_body_from_ramp (tree fndecl) { - tree body; + /* Sanity-check and punt if we have a nonsense tree because of earlier + parse errors, perhaps. */ + if (!current_binding_level + || current_binding_level->kind != sk_function_parms) + return NULL_TREE; + /* Once we've tied off the original user-authored body in fn_body. Start the replacement synthesized ramp body. */ + tree body; if (use_eh_spec_block (fndecl)) { body = pop_stmt_list (TREE_OPERAND (current_eh_spec_block, 0));