From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 43532 invoked by alias); 22 Nov 2018 23:39:55 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 43518 invoked by uid 89); 22 Nov 2018 23:39:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=oliva, NOP_EXPR, nop_expr, same_type_p X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 22 Nov 2018 23:39:53 +0000 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 43577C057F2A; Thu, 22 Nov 2018 23:39:52 +0000 (UTC) Received: from free.home (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EEC8810002B9; Thu, 22 Nov 2018 23:39:51 +0000 (UTC) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTP id wAMNddkb190340; Thu, 22 Nov 2018 21:39:39 -0200 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, nathan@acm.org Subject: [PATCH] [PR85569] skip constexpr target_expr constructor dummy type conversion Date: Thu, 22 Nov 2018 23:39:00 -0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SW-Source: 2018-11/txt/msg01969.txt.bz2 The testcase is the work-around testcase for the PR; even that had started failing. The problem was that, when unqualifying the type of a TARGET_EXPR, we'd create a variant of the type, then request the conversion of the TARGET_EXPR_INITIAL to that variant type. Though the types are different pointer-wise, they're the same_type_p, so the resulting modified expr compares cp_tree_equal to the original, which maybe_constant_value flags as an error. There's no reason to construct an alternate TARGET_EXPR or CONSTRUCTOR just because of an equivalent type, except for another spot that expected pointer equality that would no longer be satisfied. Without relaxing the assert in constexpr_call_hasher::equal, g++.robertl/eb73.C would trigger an assertion failure. Regstrapped on i686- and x86_64-linux-gnu. Ok to install? for gcc/cp/ChangeLog PR c++/85569 * constexpr.c (adjust_temp_type): Test for type equality with same_type_p. for gcc/testsuite PR c++/85569 * g++.dg/cpp1z/pr85569.C: New. --- gcc/cp/constexpr.c | 4 + gcc/testsuite/g++.dg/cpp1z/pr85569.C | 93 ++++++++++++++++++++++++++++++= ++++ 2 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/pr85569.C diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 92fd2b2d9d59..bb5d1301b332 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -1060,7 +1060,7 @@ constexpr_call_hasher::equal (constexpr_call *lhs, co= nstexpr_call *rhs) { tree lhs_arg =3D TREE_VALUE (lhs_bindings); tree rhs_arg =3D TREE_VALUE (rhs_bindings); - gcc_assert (TREE_TYPE (lhs_arg) =3D=3D TREE_TYPE (rhs_arg)); + gcc_assert (same_type_p (TREE_TYPE (lhs_arg), TREE_TYPE (rhs_arg))); if (!cp_tree_equal (lhs_arg, rhs_arg)) return false; lhs_bindings =3D TREE_CHAIN (lhs_bindings); @@ -1276,7 +1276,7 @@ cxx_eval_builtin_function_call (const constexpr_ctx *= ctx, tree t, tree fun, static tree adjust_temp_type (tree type, tree temp) { - if (TREE_TYPE (temp) =3D=3D type) + if (TREE_TYPE (temp) =3D=3D type || same_type_p (TREE_TYPE (temp), type)) return temp; /* Avoid wrapping an aggregate value in a NOP_EXPR. */ if (TREE_CODE (temp) =3D=3D CONSTRUCTOR) diff --git a/gcc/testsuite/g++.dg/cpp1z/pr85569.C b/gcc/testsuite/g++.dg/cp= p1z/pr85569.C new file mode 100644 index 000000000000..aec543041a0f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/pr85569.C @@ -0,0 +1,93 @@ +// { dg-do compile { target c++17 } } + +#include +#include + +#define LIFT_FWD(x) std::forward(x) + +template +inline +constexpr +auto +equal( + T &&t) +{ + return [t =3D std::forward(t)](const auto& obj) + -> decltype(obj =3D=3D t) + { + return obj =3D=3D t; + }; +} + +template +struct is_tuple_invocable; + +template +struct is_tuple_invocable> +{ + using type =3D typename std::is_invocable::type; +}; + +template +inline +constexpr +auto +compose( + F&& f +) + noexcept +-> F +{ + return std::forward(f); +} + +namespace detail { + template + inline + constexpr + auto + compose( + std::true_type, + F&& f, + Tail&& tail, + T&& ... objs) + noexcept(noexcept(f(tail(std::forward(objs)...)))) + -> decltype(f(tail(std::forward(objs)...))) + { + return f(tail(std::forward(objs)...)); + } +} +template +inline +constexpr +auto +compose( + F&& f, + Fs&&... fs) +{ + return [f =3D std::forward(f), tail =3D compose(std::forward(fs).= ..)] + (auto&& ... objs) + -> decltype(detail::compose(typename std::is_invocable(fs)...)), decltype(objs)...>::type{}, + f, + compose(std::forward(fs)...), + LIFT_FWD(objs)...)) + { + using tail_type =3D decltype(compose(std::forward(fs)...)); +=20=20=20=20 +#ifndef NOT_VIA_TUPLE + using args_type =3D std::tuple; + constexpr auto unitail =3D typename is_tuple_invocable::type{}; +#else + constexpr auto unitail =3D typename std::is_invocable::type{}; +#endif + + return detail::compose(unitail, f, tail, LIFT_FWD(objs)...); + }; +} + +template +constexpr auto eq =3D equal(N); + +static_assert(compose(eq<3>, + std::plus<>{})(1,2), + "compose is constexpr"); --=20 Alexandre Oliva, freedom fighter https://FSFLA.org/blogs/lxo Be the change, be Free! FSF Latin America board member GNU Toolchain Engineer Free Software Evangelist Hay que enGNUrecerse, pero sin perder la terGNUra jam=C3=A1s-GNUChe