From patchwork Sat Aug 8 09:23:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1342469 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org 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=NZwFuGNO; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4BNxbr2tBDz9sPB for ; Sat, 8 Aug 2020 19:23:18 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DB3D7384240F; Sat, 8 Aug 2020 09:23:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DB3D7384240F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1596878595; bh=wU43qIKb8WlCeu8VN77CgWpRtR+cZzZ4Pp7XEEr5wO4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=NZwFuGNOf3H+/f6mEfm+Rn/xCFTwMFH2eZo7FKFwJw4tPYNqUJddCXnSgjiKrSe/+ JwE4bsRyx2nMtUxzxMfdSFrJH3v+Z/dpNS7q2pmBZMPQ2ts7TQcaFVBKfqqKcprnc0 U6lAYf3sTM2t7oRWqPnqwAQ6DXEn4BamO6D3H49o= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by sourceware.org (Postfix) with ESMTP id DECD23857011 for ; Sat, 8 Aug 2020 09:23:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DECD23857011 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-381-9XSh6l_WNUC1Ep2FR-v2qw-1; Sat, 08 Aug 2020 05:23:11 -0400 X-MC-Unique: 9XSh6l_WNUC1Ep2FR-v2qw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 222931005504 for ; Sat, 8 Aug 2020 09:23:10 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-113-174.ams2.redhat.com [10.36.113.174]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC92E108AA; Sat, 8 Aug 2020 09:23:09 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id 0789N6OF024740; Sat, 8 Aug 2020 11:23:07 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 0789N6Kq024739; Sat, 8 Aug 2020 11:23:06 +0200 Date: Sat, 8 Aug 2020 11:23:06 +0200 To: Jason Merrill Subject: [PATCH] c++; Fix constexpr evaluation of SPACESHIP_EXPR [PR96497] Message-ID: <20200808092306.GA9984@tucnak> MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi! The following valid testcase is rejected, because cxx_eval_binary_expression is called on the SPACESHIP_EXPR with lval = true, as the address of the spaceship needs to be passed to a method call. After recursing on the operands and calling genericize_spaceship which turns it into a TARGET_EXPR with initialization, we call cxx_eval_constant_expression on it which succeeds, but then we fall through into code that will VERIFY_CONSTANT (r) which FAILs because it is an address of a variable. Rather than avoiding that for lval = true and SPACESHIP_EXPR, the patch just tail calls cxx_eval_constant_expression - I believe that call should perform all the needed verifications. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk (and later for 10.3)? 2020-08-08 Jakub Jelinek PR c++/96497 * constexpr.c (cxx_eval_binary_expression): For SPACESHIP_EXPR, tail call cxx_eval_constant_expression after genericize_spaceship to avoid undesirable further VERIFY_CONSTANT. * g++.dg/cpp2a/spaceship-constexpr3.C: New test. Jakub --- gcc/cp/constexpr.c.jj 2020-08-06 11:35:12.997122440 +0200 +++ gcc/cp/constexpr.c 2020-08-07 13:30:28.732376843 +0200 @@ -3085,8 +3085,8 @@ cxx_eval_binary_expression (const conste else if (code == SPACESHIP_EXPR) { r = genericize_spaceship (type, lhs, rhs); - r = cxx_eval_constant_expression (ctx, r, lval, non_constant_p, - overflow_p); + return cxx_eval_constant_expression (ctx, r, lval, non_constant_p, + overflow_p); } if (r == NULL_TREE) --- gcc/testsuite/g++.dg/cpp2a/spaceship-constexpr3.C.jj 2020-08-07 13:37:34.883410112 +0200 +++ gcc/testsuite/g++.dg/cpp2a/spaceship-constexpr3.C 2020-08-07 13:38:09.988918586 +0200 @@ -0,0 +1,7 @@ +// PR c++/96497 +// { dg-do compile { target c++20 } } + +#include + +static_assert(std::partial_ordering(std::strong_ordering::less) < 0); +static_assert(std::partial_ordering(1 <=> 2) < 0);