From patchwork Thu Feb 2 18:09:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 64159 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3DC0F3858C74 for ; Thu, 2 Feb 2023 18:10:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3DC0F3858C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675361424; bh=kYILftIF0i8Rm9r+Yk9cPXOri/2qLIbdA2NNlKmWwwc=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=JEatMjKPQLMbxYOoOFJ4Vu3ZFdV/Tsvw5t5+IjeJl/bOEmemCum7ZKMWwgnCz55LM f/WIx+hZyjUkLX5cJVibPvOWiB5LqVM/gkFLlhm+SY/bcuzNX0bsj/vLrMWTequz3B 9CwdSSeiusftbYW99/y7l/3SlIYUdDaJIYY71Zh4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id BBACF3858C52 for ; Thu, 2 Feb 2023 18:09:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BBACF3858C52 Received: from mail-yb1-f200.google.com (mail-yb1-f200.google.com [209.85.219.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-618-pLWnUg5EPr-mT8pLmM5pww-1; Thu, 02 Feb 2023 13:09:54 -0500 X-MC-Unique: pLWnUg5EPr-mT8pLmM5pww-1 Received: by mail-yb1-f200.google.com with SMTP id a4-20020a5b0004000000b006fdc6aaec4fso2446126ybp.20 for ; Thu, 02 Feb 2023 10:09:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kYILftIF0i8Rm9r+Yk9cPXOri/2qLIbdA2NNlKmWwwc=; b=fZvcf57E81uuXZ2ea5HOvVYYRKfUi6q6gAvieyRDni0uW1QDP0R9kXCWffCJLjArlv hEMu3jXHFTif5QtYI0nu7D/YZW/i409s+OLeBGHuJ8qZoa2svGRU9s2gNXj8/FCzLLFc 3PQw78/+GOMogPuemt3sR5lLc4ur4Ir16zUamZSr+NV0jzHGJmjbSiNvL6PgfHWBrEL7 MVWcitFOwG3QEjPHWiZkt8gzQcsp3mrAdVvi29oh+rkMewTU9Mop+1w0rXCbQjmLfNpL VnhEk/RTdRgN04h/T7oeaS3jluBV2LE6JucGbFPwdcRB+2Ge99IoWfTSGOUnCsJEVj3r L60Q== X-Gm-Message-State: AO0yUKWhzwVrL5iiP9nH2tPJxlVufMINUVsdLRAGHQbqg9S6bdPyVCaG kuANNFOsxs35j54uJPo/HN8PhWJoR6bTQ13Yv/RugpH6+jcZL6Vr0uXPEaP2vUwUt7WZnmrrkA0 wRxX0wnlfBWTYvWTg2MnoUKaaea5cSdKnBxkDfxxhR5ffAPHKldOBu9j/dIK323TQ6cU= X-Received: by 2002:a81:a014:0:b0:519:3389:e30b with SMTP id x20-20020a81a014000000b005193389e30bmr4502627ywg.5.1675361393160; Thu, 02 Feb 2023 10:09:53 -0800 (PST) X-Google-Smtp-Source: AK7set9xcqkxWF/bROfgtLU0M9gFfObSuSckvaOkgF5EJEtP3hxnawCL9Omz+mi/ABUHfRVJkq/dSA== X-Received: by 2002:a81:a014:0:b0:519:3389:e30b with SMTP id x20-20020a81a014000000b005193389e30bmr4502611ywg.5.1675361392821; Thu, 02 Feb 2023 10:09:52 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id i15-20020a05620a27cf00b006fba0a389a4sm155123qkp.88.2023.02.02.10.09.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:09:52 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: spurious ADDR_EXPR after overload set pruning [PR107461] Date: Thu, 2 Feb 2023 13:09:50 -0500 Message-Id: <20230202180950.3469931-1-ppalka@redhat.com> X-Mailer: git-send-email 2.39.1.388.g2fc9e9ca3c MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Here the ahead-of-time overload set pruning in finish_call_expr is unintentionally returning a CALL_EXPR whose pruned callee is wrapped in an ADDR_EXPR, despite the original callee not being wrapped in an ADDR_EXPR. This ends up causing a bogus declaration matching error in the below testcase because the call to min in #1 is expressed as a CALL_EXPR to ADDR_EXPR to FUNCTION_DECL, whereas the level-lowered call to min in #2 is expressed instead as a CALL_EXPR to FUNCTION_DECL. This patch fixes this by stripping this ADDR_EXPR appropriately. Thus the first call to min now gets expresssed as a CALL_EXPR to FUNCTION_DECL, matching the form it had before r12-6075-g2decd2cabe5a4f. Bootstrapped and regtested on x86_64-pc-linu-xgnu, does this look OK for trunk and 12? PR c++/107461 gcc/cp/ChangeLog: * semantics.cc (finish_call_expr): Strip ADDR_EXPR from the selected callee during overload set pruning. gcc/testsuite/ChangeLog: * g++.dg/template/friend75.C: New test. --- gcc/cp/semantics.cc | 15 +++++++++----- gcc/testsuite/g++.dg/template/friend75.C | 26 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/friend75.C diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index b3afea85196..fe9262a257f 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -2957,13 +2957,18 @@ finish_call_expr (tree fn, vec **args, bool disallow_virtual, if (TREE_CODE (result) == CALL_EXPR && really_overloaded_fn (orig_fn)) { - orig_fn = CALL_EXPR_FN (result); - if (TREE_CODE (orig_fn) == COMPONENT_REF) + tree sel_fn = CALL_EXPR_FN (result); + if (TREE_CODE (sel_fn) == COMPONENT_REF) { /* The non-dependent result of build_new_method_call. */ - orig_fn = TREE_OPERAND (orig_fn, 1); - gcc_assert (BASELINK_P (orig_fn)); - } + sel_fn = TREE_OPERAND (sel_fn, 1); + gcc_assert (BASELINK_P (sel_fn)); + } + else if (TREE_CODE (sel_fn) == ADDR_EXPR) + /* Undo the ADDR_EXPR callee wrapping performed by build_over_call + since the original callee didn't have it. */ + sel_fn = TREE_OPERAND (sel_fn, 0); + orig_fn = sel_fn; } result = build_call_vec (TREE_TYPE (result), orig_fn, orig_args); diff --git a/gcc/testsuite/g++.dg/template/friend75.C b/gcc/testsuite/g++.dg/template/friend75.C new file mode 100644 index 00000000000..800d3043c8a --- /dev/null +++ b/gcc/testsuite/g++.dg/template/friend75.C @@ -0,0 +1,26 @@ +// PR c++/107461 +// { dg-do compile { target c++11 } } + +template +constexpr T min(T t0, T t1) { + return t0 < t1 ? t0 : t1; +} + +template +struct Matrix; + +template +Matrix +operator+(Matrix const& lhs, Matrix const& rhs); // #1 + +template +struct Matrix { + template + friend Matrix + operator+(Matrix const& lhs, Matrix const& rhs); // #2 +}; + +void f() { + Matrix<1> a; + a+a; +}