From patchwork Wed Jun 23 23:37:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1496313 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=mkjS52CE; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G9KSl6FhCz9sWX for ; Thu, 24 Jun 2021 09:37:58 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 817BE397EC0E for ; Wed, 23 Jun 2021 23:37:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 817BE397EC0E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1624491475; bh=EQLIzrdvNluE4vqZLBLbPeawV+18XUfz0mo2iVDxiMk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=mkjS52CEFZJT0YsuLhV6XxwHsq8DCMngZja/kbLLZMu09aQdtlloYQxjNMDtbf1Q4 d44E+96n574Hyn66qhzTpsXy8mceE8tnPHI/Mgqebka5xbu+SLGcWDpqrcKahkb3vM 8EDFey9hkte9jwgjm3YXYay9lVO1lwU+NDsfSG1g= 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.133.124]) by sourceware.org (Postfix) with ESMTP id CA380383D02A for ; Wed, 23 Jun 2021 23:37:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CA380383D02A Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-338-Qc53uKegNAyTlXYb_nDDhw-1; Wed, 23 Jun 2021 19:37:30 -0400 X-MC-Unique: Qc53uKegNAyTlXYb_nDDhw-1 Received: by mail-qt1-f197.google.com with SMTP id g4-20020ac80ac40000b029024ead0ebb62so4349933qti.13 for ; Wed, 23 Jun 2021 16:37:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=EQLIzrdvNluE4vqZLBLbPeawV+18XUfz0mo2iVDxiMk=; b=Oe9oWJnj8XK0iWIy3ulmpipbI2R7eBYgYHINiMS6LiIUBJ0djaL+W0bzsv0TdhswfW ex4nSSHY7M/TCtdAzIyvKnkGXHaAY4LT0fP+umkKX/9mPjsspofACCP9i9M8mussHsAh D8tzopg2VXrqlxED4u/Y4In5W/kLihx/bkeiRZdv4gcX8x5kNpyv10HQq2HHX/T1dzlv ZfKW4wXSCdS+/6+EV/iVM4CYMXW6lEuJtLzhFmlVNkdqFziRiFqv7dQiUXphnUl3nc9U LR9K8PbO03K+NKcPdIUI9l9uw1RQ9jx2Rzyc1nlVN8c0FP/wbHor+9dO0cXE9K4VG2gE BjdA== X-Gm-Message-State: AOAM531Qj9zEPhu+SjWp3evB7noh0MdAy/slZj9aewN8eviA7AfB6hrB YB8T0BGLGWpAUOsqvgckV0aYvRn/y0GtZfL7szvqKnMdmqBTDSpkHnYN6affR0vZ/GEs4yvl/Gt eNQOG/1lHukY8FrFEVCw/mRbIJXLZCDuMJJgacL5uAvSHr+IV1azxFEoGveiTPk2Pt4Q= X-Received: by 2002:a05:620a:e04:: with SMTP id y4mr2720798qkm.196.1624491449744; Wed, 23 Jun 2021 16:37:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxvKJDuT2rdoLMRCN+tiF/VIK3i6oUNEclmH6jXldz20V1U0PdDSFNszQXXWAiY8aZ24C3Jw== X-Received: by 2002:a05:620a:e04:: with SMTP id y4mr2720776qkm.196.1624491449409; Wed, 23 Jun 2021 16:37:29 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id 189sm1085069qkh.45.2021.06.23.16.37.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 16:37:29 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: requires-expression folding [PR101182] Date: Wed, 23 Jun 2021 19:37:27 -0400 Message-Id: <20210623233727.2288297-1-ppalka@redhat.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.7 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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_SBL, URIBL_SBL_A autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Here we're crashing because cp_fold_function walks into the (templated) requirements of a requires-expression outside a template, but the folding routines aren't prepared to handle templated trees. This patch fixes this by making cp_fold use evaluate_requires_expr to fold a requires-expression as a whole, which also means we no longer need to explicitly do so during gimplification. (We don't immediately fold non-dependent requires-expressions at parse time for sake of better diagnostics in case one appears as the condition of a failed static_assert.) Bootstrapped and regtested on x86_64-pc-linux-gnu, also tested on cmcstl2 and range-v3, does this look OK for trunk/11? PR c++/101182 gcc/cp/ChangeLog: * constraint.cc (evaluate_requires_expr): Adjust function comment. * cp-gimplify.c (cp_genericize_r) : Move to ... (cp_fold) : ... here. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-requires27.C: New test. --- gcc/cp/constraint.cc | 2 +- gcc/cp/cp-gimplify.c | 10 ++++------ gcc/testsuite/g++.dg/cpp2a/concepts-requires27.C | 10 ++++++++++ 3 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-requires27.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 74b16d27101..286332ba2a7 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3340,7 +3340,7 @@ evaluate_concept_check (tree check) } /* Evaluate the requires-expression T, returning either boolean_true_node - or boolean_false_node. This is used during gimplification and constexpr + or boolean_false_node. This is used during folding and constexpr evaluation. */ tree diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 96d91b6ef2f..33e10556e32 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -1465,12 +1465,6 @@ cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data) TARGET_EXPR_NO_ELIDE (stmt) = 1; break; - case REQUIRES_EXPR: - /* Emit the value of the requires-expression. */ - *stmt_p = evaluate_requires_expr (stmt); - *walk_subtrees = 0; - break; - case TEMPLATE_ID_EXPR: gcc_assert (concept_check_p (stmt)); /* Emit the value of the concept check. */ @@ -2708,6 +2702,10 @@ cp_fold (tree x) x = r; break; + case REQUIRES_EXPR: + x = evaluate_requires_expr (x); + break; + default: return org_x; } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires27.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires27.C new file mode 100644 index 00000000000..87a759a689a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires27.C @@ -0,0 +1,10 @@ +// PR c++/101182 +// { dg-do compile { target concepts } } + +int a; +int g(bool); + +int f() { + g(requires { a++; }); + return requires { a++; }; +}