From patchwork Sun Oct 3 20:06:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 45749 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ADC8D3858420 for ; Sun, 3 Oct 2021 20:07:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ADC8D3858420 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633291636; bh=MxXYVqe/P+fNpUEd31rLXUWUBVnywceXSeZxU1/ZLJU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=NTsSK93oNBSJfFM3NpEF3O+IVIlP2yA633aoD1pKn94XIUaG87Rtw7bLaa5xDIv2s CQS0gtXF67GGCluNKWZtQkJNdI4IKYwdJF7BxtFC2PzI3/cKJ9ZfJrDMVoH/H2/bKH CPjgphIuRHBos5Zp4se+JU8sGlzj1z0CDWBsrWdw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id 1186F3858D39 for ; Sun, 3 Oct 2021 20:06:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1186F3858D39 Received: by mail-wm1-x32e.google.com with SMTP id g198-20020a1c20cf000000b0030d60cd7fd6so2901483wmg.0 for ; Sun, 03 Oct 2021 13:06:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :mime-version:content-transfer-encoding; bh=MxXYVqe/P+fNpUEd31rLXUWUBVnywceXSeZxU1/ZLJU=; b=ggMhFts+3t5xecHlxxzDUirfv6YCETRaYltbZfKRgqZs6KMydsosul1uURBE5CrssG jww0TkVtlNOkNa4d3qUwRPal/8NVyUbGJD7HAsHTgnOx3toFCXs062NwcF/EjpB1wCof vcc3g722vmG0oqGREBALophQLRUoaqCAMC22H9Gdq4qGZjQDoF3O6/IkQCn06ylhWmTJ OUVt3rhb6qM6w1l8EVSnS5tXigewm+3HdRnOyS9EI0kyFyOZsoM8mYLZnEKPD781ikBt GQlurCzMYvv9ZBz7slceKaOedpvo12sLx+e5mnXd01pLFvAF0wtYexMm5Ro26J+QR+PU ndhg== X-Gm-Message-State: AOAM533iKxz/WTl9GFgDxftY5RfSCSQxwjqE8aEobyIFxuf256idWfS4 73BTh1i8MbBGOHUDgmr8BcorNcBgCmFasA== X-Google-Smtp-Source: ABdhPJz+tvlY9tjKmCK6Vz4MjY6zSCBFylVC63DlKRmHk6twe42H/Kf9NynRSxno/WC/2nZfMFsTdw== X-Received: by 2002:a1c:4c04:: with SMTP id z4mr8141099wmf.115.1633291604506; Sun, 03 Oct 2021 13:06:44 -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 u1sm13652205wmc.29.2021.10.03.13.06.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Oct 2021 13:06:44 -0700 (PDT) X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [pushed] coroutines: Fail with a sorry when presented with a VLA [PR 101765]. Date: Sun, 3 Oct 2021 21:06:38 +0100 Message-Id: <20211003200638.67764-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.24.3 (Apple Git-128) MIME-Version: 1.0 X-Spam-Status: No, score=-8.5 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 autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Iain Sandoe via Gcc-patches From: Iain Sandoe Reply-To: iain@sandoe.co.uk Cc: Iain Sandoe Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" We do not support this yet. fail with a sorry instead of ICEing. tested on x86_64,powerpc64le-linux, x86_64-darwin, cppcoro, folly. pushed to master as obvious, thanks Iain Signed-off-by: Iain Sandoe PR c++/101765 gcc/cp/ChangeLog: * coroutines.cc (register_local_var_uses): Emit a sorry if we encounter a VLA in the coroutine local variables. gcc/testsuite/ChangeLog: * g++.dg/coroutines/pr101765.C: New test. --- gcc/cp/coroutines.cc | 10 +++++ gcc/testsuite/g++.dg/coroutines/pr101765.C | 45 ++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 gcc/testsuite/g++.dg/coroutines/pr101765.C diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index 377b90c777f..9017902e6fb 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -3927,6 +3927,16 @@ register_local_var_uses (tree *stmt, int *do_subtree, void *d) if (local_var.is_static) continue; + poly_uint64 size; + if (TREE_CODE (lvtype) == ARRAY_TYPE + && !poly_int_tree_p (DECL_SIZE_UNIT (lvar), &size)) + { + sorry_at (local_var.def_loc, "variable length arrays are not" + " yet supported in coroutines"); + /* Ignore it, this is broken anyway. */ + continue; + } + lvd->local_var_seen = true; /* If this var is a lambda capture proxy, we want to leave it alone, and later rewrite the DECL_VALUE_EXPR to indirect through the diff --git a/gcc/testsuite/g++.dg/coroutines/pr101765.C b/gcc/testsuite/g++.dg/coroutines/pr101765.C new file mode 100644 index 00000000000..49a49d11299 --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/pr101765.C @@ -0,0 +1,45 @@ +// We cannot compile this yet, much run it - but one day it might be +// feasible, so do the minimum for now. +// { dg-additional-options " -fsyntax-only -Wno-vla" } + +#include "coro.h" + +// boiler-plate for tests of codegen +#include "coro1-ret-int-yield-int.h" + +struct coro1 +foo (int arg) noexcept +{ + PRINTF ("foo arg = %d\n", arg); + char arr[arg]; /* { dg-message "sorry, unimplemented: variable length arrays are not yet supported in coroutines" "" { target *-*-* } } */ + if (arg < 4) + co_return -6174; + else + for (int i = 0; i < arg; ++i) arr[i] = (char) i; + co_yield (int) arr[2]; + co_return (int) arr[3]; +} + +int main () +{ + PRINT ("main: create coro1"); + struct coro1 x = foo (10); + PRINT ("main: got coro1 - resuming"); + if (x.handle.done()) + abort(); + x.handle.resume(); + PRINT ("main: after resume"); + int y = x.handle.promise().get_value(); + if ( y == -6174 ) + { + PRINT ("main: saw -6174"); + return 1; + } + else if ( y != 2 ) + abort; + x.handle.resume(); + y = x.handle.promise().get_value(); + if ( y != 3 ) + abort (); + return 0; +}