From patchwork Thu Nov 22 23:39:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 1002074 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-490767-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.b="lKDxC/Dq"; 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 431GBs4btrz9s0n for ; Fri, 23 Nov 2018 10:40:02 +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:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=Gy5ZpaZA/szxAk/3 SMyXKn7BlQza1MUFkYrW2qzYNhf0a/5WOtjhV9QvuxCtfHnTj0G8AKriuN3pCrzv k5OkV6Mk9Ouf+Bqz+hSzECuAiZuPqvKKhzCM5GDTxMwEv98YpOgWfZISnVJjyauV pIrn3viLGxELw6ycc0R0R+oV00o= 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:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=vcLiX6iYRMyS9emPg1mf5h bfcT0=; b=lKDxC/DqGFyfG/NNq8TbbAnjlXWms3ymV94ymdRKMIY1pxoyVNd7aq iHfz3rC8VXFQoJltWwHtv4iT2zhYRDTOoidFhjtAQIlwpc3uInTlbk/HioS3WX0Q Dkn09/e72fPdWm5C9T4Uxdhly7x2hHoJGzJGAx+2STh4UrKidSHkQ= 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-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 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 21:39:39 -0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 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, constexpr_call *rhs) { tree lhs_arg = TREE_VALUE (lhs_bindings); tree rhs_arg = TREE_VALUE (rhs_bindings); - gcc_assert (TREE_TYPE (lhs_arg) == 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 = 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) == type) + if (TREE_TYPE (temp) == type || same_type_p (TREE_TYPE (temp), type)) return temp; /* Avoid wrapping an aggregate value in a NOP_EXPR. */ if (TREE_CODE (temp) == CONSTRUCTOR) diff --git a/gcc/testsuite/g++.dg/cpp1z/pr85569.C b/gcc/testsuite/g++.dg/cpp1z/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 = std::forward(t)](const auto& obj) + -> decltype(obj == t) + { + return obj == t; + }; +} + +template +struct is_tuple_invocable; + +template +struct is_tuple_invocable> +{ + using type = 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 = std::forward(f), tail = 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 = decltype(compose(std::forward(fs)...)); + +#ifndef NOT_VIA_TUPLE + using args_type = std::tuple; + constexpr auto unitail = typename is_tuple_invocable::type{}; +#else + constexpr auto unitail = typename std::is_invocable::type{}; +#endif + + return detail::compose(unitail, f, tail, LIFT_FWD(objs)...); + }; +} + +template +constexpr auto eq = equal(N); + +static_assert(compose(eq<3>, + std::plus<>{})(1,2), + "compose is constexpr");