From patchwork Tue Feb 11 08:18:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1236198 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=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519322-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=SurpZw0q; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Jfu9kX5L; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48GwfF5MSFz9sRL for ; Tue, 11 Feb 2020 19:18:59 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:content-type :content-transfer-encoding; q=dns; s=default; b=lPdTWMIqE7T0QT10 Y3bAVL9gUSQ6XdYYb6ktr6cHeZP/xJLdvCQALt7Taf7Rd75L2y4TC5LLhXVWFbwz QAYMUH0pUvFI+TqQz4GOe59X13ZYvFz3bXVPifjrXpPjBXgHoTY18hY1NH/TJkcL lXWvXcQ2Dbz83YqReUwzRUf70mA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:content-type :content-transfer-encoding; s=default; bh=HlnftFqBTCu/dpDN2sizut mRYgs=; b=SurpZw0qRRrpABNyoZBIVSAm5clm9BNvDyP70kR2819xidAxFlvNV+ qRrEpzB3lNd6VVv0WWeF9ixBqIVmNOllnhBGDrpmDHiJJjy5v/XRpJCE7u7Bb744 FSntzcf+mQ4Y/JrRmiLsdWIcJQgdAMLYTkMcjoLYaJ0E0qFVsg/AU= Received: (qmail 72393 invoked by alias); 11 Feb 2020 08:18:51 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 71904 invoked by uid 89); 11 Feb 2020 08:18:51 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=comp X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (207.211.31.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Feb 2020 08:18:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581409128; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=bzkOstyj3AZ9H8AyJ+AJPV7r15PyFQl6db4eao5S4LQ=; b=Jfu9kX5LrsTKSEQT6tNC0cqbWyeVvr4La2CcOJKlVJ3WeZHvmAa3tjK5Wr/EReMx39oUCX 68dCbphkEu39QFjevKKrZIoVZvKKIypxWreQAnRd18D5GlsmfTOpt10Fy33tbmEGVHiyt8 8LDWebJ3eKr0haWNWsF2hUkHipsz7EU= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-113-yG10nzgxMpyhopUjfRB41w-1; Tue, 11 Feb 2020 03:18:46 -0500 Received: by mail-wr1-f71.google.com with SMTP id p8so6495641wrw.5 for ; Tue, 11 Feb 2020 00:18:46 -0800 (PST) Received: from barrymore.redhat.com ([193.85.242.128]) by smtp.gmail.com with ESMTPSA id x10sm4223882wrp.58.2020.02.11.00.18.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Feb 2020 00:18:43 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [committed] c++: Fix static initialization from <=>. Date: Tue, 11 Feb 2020 09:18:42 +0100 Message-Id: <20200211081842.18866-1-jason@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes Constant evaluation of genericize_spaceship produced a CONSTRUCTOR, which we then wanted to bind to a reference, which we can't do. So wrap the result in a TARGET_EXPR so we get something with an address. We also need to handle treating the result of cxx_eval_binary_expression as a glvalue for SPACESHIP_EXPR. My earlier change to add uid_sensitive to maybe_constant_value was wrong; we don't even look at the cache when manifestly_const_eval, and I failed to adjust the later call to cxx_eval_outermost_constant_expr. Tested x86_64-pc-linux-gnu, applying to trunk. gcc/cp/ChangeLog 2020-02-11 Jason Merrill PR c++/93650 PR c++/90691 * constexpr.c (maybe_constant_value): Correct earlier change. (cxx_eval_binary_expression) [SPACESHIP_EXPR]: Pass lval through. * method.c (genericize_spaceship): Wrap result in TARGET_EXPR. --- gcc/cp/constexpr.c | 12 +++++------- gcc/cp/method.c | 3 +++ gcc/testsuite/g++.dg/cpp2a/spaceship-constexpr2.C | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/spaceship-constexpr2.C base-commit: a6ee556c7659877bb59b719f11ca2153e86ded59 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 6495cf88e69..bf7a2643003 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -2834,7 +2834,7 @@ cxx_fold_pointer_plus_expression (const constexpr_ctx *ctx, tree t, static tree cxx_eval_binary_expression (const constexpr_ctx *ctx, tree t, - bool /*lval*/, + bool lval, bool *non_constant_p, bool *overflow_p) { tree r = NULL_TREE; @@ -2902,7 +2902,7 @@ cxx_eval_binary_expression (const constexpr_ctx *ctx, tree t, else if (code == SPACESHIP_EXPR) { r = genericize_spaceship (type, lhs, rhs); - r = cxx_eval_constant_expression (ctx, r, false, non_constant_p, + r = cxx_eval_constant_expression (ctx, r, lval, non_constant_p, overflow_p); } @@ -6686,13 +6686,11 @@ maybe_constant_value (tree t, tree decl, bool manifestly_const_eval, r = unshare_expr_without_location (r); protected_set_expr_location (r, EXPR_LOCATION (t)); } - if (r != t || TREE_CONSTANT (t) || !manifestly_const_eval) - return r; - /* If we cached this as non-constant and we need a constant value, try - again; we might have failed before due to UID_SENSITIVE. */ + return r; } - r = cxx_eval_outermost_constant_expr (t, true, true, false, false, decl); + r = cxx_eval_outermost_constant_expr (t, true, true, false, false, + decl, uid_sensitive); gcc_checking_assert (r == t || CONVERT_EXPR_P (t) || TREE_CODE (t) == VIEW_CONVERT_EXPR diff --git a/gcc/cp/method.c b/gcc/cp/method.c index fef19e18196..cfc37bc1b17 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -1075,6 +1075,9 @@ genericize_spaceship (tree type, tree op0, tree op1) comp = fold_build2 (EQ_EXPR, boolean_type_node, op0, op1); r = fold_build3 (COND_EXPR, type, comp, eq, r); + /* Wrap the whole thing in a TARGET_EXPR like build_conditional_expr_1. */ + r = get_target_expr (r); + return r; } diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-constexpr2.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-constexpr2.C new file mode 100644 index 00000000000..02f92b10aef --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-constexpr2.C @@ -0,0 +1,14 @@ +// PR c++/93650 +// { dg-do compile { target c++2a } } + +namespace std { + using type = enum _Ord { less }; + class strong_ordering { + type _M_value; + constexpr strong_ordering(_Ord) : _M_value() {} + static const strong_ordering less; + static strong_ordering equal; + static strong_ordering greater; + } constexpr strong_ordering::less(_Ord::less); + auto v = 1 <=> 2; +}