From patchwork Mon Feb 28 17:56:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1599053 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=VeCNCFX4; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4K6p3S2b1Sz9sFv for ; Tue, 1 Mar 2022 04:56:35 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 74DA23858036 for ; Mon, 28 Feb 2022 17:56:32 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [IPv6:2607:f8b0:4864:20::f36]) by sourceware.org (Postfix) with ESMTPS id 2BE523858C60 for ; Mon, 28 Feb 2022 17:56:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2BE523858C60 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qv1-xf36.google.com with SMTP id j11so13938552qvy.0 for ; Mon, 28 Feb 2022 09:56:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:message-id:date:mime-version:user-agent:content-language:to :cc:from:subject; bh=r6z/yfl8bCoyw/1l6ZvPlrinKf9m3PmkkPENcW+hHXA=; b=VeCNCFX4kI4wK6JfChETGSLUXmMTvPz0n3hkbvHfEuXM4qmf+7rdUZrOF2MbGyP1v6 qQ4NjgotXDP1AoCuPi58jAk8cqmmd3MpDSluQZ9yl3rC+2zfWFoG5lmtfyUKHsjSgLHN USfA00hH9QAfrjHUKMximjEexs6FzvWMTEqW2iVfN80upNQiE1TlH862g47YFfll95gP xXLSm25bWT9iuJoYUzBDsrAzh+6QrxCKdG3IcRdseNYJZEOe3ndLRugcW3ls5J4XIyHy ako9VqOLyjOyVqoQyRlH0BYNyZD3jBOgSfEKv/8L/cyfX/Xa2KSBq2MKGk92tXe0+Hej ZYrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:message-id:date:mime-version:user-agent :content-language:to:cc:from:subject; bh=r6z/yfl8bCoyw/1l6ZvPlrinKf9m3PmkkPENcW+hHXA=; b=HC3wg3RYykQl4UaoYoolElvFM6vjGZ0u7ODeWL0cjaqMjjtF0qNQ+EoSMB/KjRHSGX ohdM1pb62RIMH0f/Y6sSKZ2US+L8q0mBdpE2TMaHlMd9t54Zox8U2mOACUPmdeWHTezy Rd5btCvJjouAhflZ+WYYxqHLLZ2igyAF936QKqjTpTwe1zImAEcY89wqxnLWy27FRl+k JA0efVuyFx6kL/f5Gk+9Pzwb9s0cvyiWQcvBdrHoA5q2KyBuCvSUuDxb2PLmwJ3NFwNz aIO417MpEY2v8pIgkNocpJtXy4ZIWukUJsQGnxRP92Zc6XArKgstrvbZxa+KH8+Wr5i9 bLbQ== X-Gm-Message-State: AOAM532tUdYn36WAgVIKeLoJ5zgjDwUNsx1lbVrdfmh+adJVIkbI2pCe x9yVZ7q5yKx5TEDAgQr1j5s= X-Google-Smtp-Source: ABdhPJytLoaXaeGvKnjf8BO2alrIlWQBT1dnb4c+Z6zZBw4QFV48b4XhhWsud+KaZimLUnUlZv0U9Q== X-Received: by 2002:a0c:e009:0:b0:432:8590:40bf with SMTP id j9-20020a0ce009000000b00432859040bfmr14467282qvk.28.1646070969682; Mon, 28 Feb 2022 09:56:09 -0800 (PST) Received: from ?IPV6:2620:10d:c0a3:1407:7a37:3822:e32e:7ad3? ([2620:10d:c091:500::2:bc71]) by smtp.googlemail.com with ESMTPSA id h188-20020a376cc5000000b00648d7e2a36bsm5403591qkc.117.2022.02.28.09.56.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 28 Feb 2022 09:56:09 -0800 (PST) Message-ID: <719e4bac-e225-8a59-5b3e-e4dd14d205c1@acm.org> Date: Mon, 28 Feb 2022 12:56:08 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Content-Language: en-US To: Iain Sandoe From: Nathan Sidwell Subject: [coroutines] expanding inside a template X-Spam-Status: No, score=-3039.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: , Cc: GCC Patches Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Iain, this is the second bug, also found in Folly and also not extracted to a testcase. We were ICEing because we ended up tsubst_copying something that had already been tsubst, leading to an assert failure (mostly such repeated tsubsting is harmless). We had a non-dependent co_await in a non-dependent-type template fn, so we processed it at definition time, and then reprocessed at instantiation time. This is not quite the right fix, as it'll make all co_awaits in a template function have dependent type. However, in practice it appears less ICEy! Exprs only have dependent type if at least one operand is dependent -- which was what you were trying to do. Coroutines have the additional wrinkle, that the current fn's type is an implicit operand. So, if the coroutine function's type is not dependent, and the operand is not dependent, we should determine the type of the co_await expression using the DEPENDENT_EXPR wrapper machinery. That allows us to determine the subexpression type, but leave its operand unchanged and then instantiate it later. I'm not sure if the std explicitly calls out this dependent-subexpr-type wrinkle. nathan Summary: The coroutine machinery attempts to process non-dependent coroutine expressions at template definition time. That's just wrong. diff --git a/9.x/src/gcc-10.x/gcc/cp/coroutines.cc b/9.x/src/gcc-10.x/gcc/cp/coroutines.cc index 91c017f0b7..d0f292f2a6 100644 --- a/9.x/src/gcc-10.x/gcc/cp/coroutines.cc +++ b/9.x/src/gcc-10.x/gcc/cp/coroutines.cc @@ -1153,7 +1153,7 @@ finish_co_await_expr (location_t kw, tree expr) /* If we don't know the promise type, we can't proceed, build the co_await with the expression unchanged. */ tree functype = TREE_TYPE (current_function_decl); - if (dependent_type_p (functype) || type_dependent_expression_p (expr)) + if (processing_template_decl) return build5_loc (kw, CO_AWAIT_EXPR, unknown_type_node, expr, NULL_TREE, NULL_TREE, NULL_TREE, integer_zero_node); @@ -1230,7 +1230,7 @@ finish_co_yield_expr (location_t kw, tree expr) /* If we don't know the promise type, we can't proceed, build the co_await with the expression unchanged. */ tree functype = TREE_TYPE (current_function_decl); - if (dependent_type_p (functype) || type_dependent_expression_p (expr)) + if (processing_template_decl) return build2_loc (kw, CO_YIELD_EXPR, unknown_type_node, expr, NULL_TREE); if (!coro_promise_type_found_p (current_function_decl, kw)) @@ -1316,7 +1316,7 @@ finish_co_return_stmt (location_t kw, tree expr) /* If we don't know the promise type, we can't proceed, build the co_return with the expression unchanged. */ tree functype = TREE_TYPE (current_function_decl); - if (dependent_type_p (functype) || type_dependent_expression_p (expr)) + if (processing_template_decl) { /* co_return expressions are always void type, regardless of the expression type. */ -- 2.30.2