From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++; Fix constexpr evaluation of SPACESHIP_EXPR [PR96497] Message-ID: <20200808092306.GA9984@tucnak> Reply-To: Jakub Jelinek 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-Type: text/plain; charset=us-ascii 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-List-Received-Date: Sat, 08 Aug 2020 09:23:14 -0000 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. --- 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); Jakub