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: 52107 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp391235wrn; Thu, 2 Feb 2023 10:10:40 -0800 (PST) X-Google-Smtp-Source: AK7set+/mTQZj5EtGDd5nswHyAmKKpBF0RetXuf7KvUhjaePvlJ1SicHCVZAnHJHzW9DqBiXqws3 X-Received: by 2002:a17:906:2496:b0:86f:5636:4712 with SMTP id e22-20020a170906249600b0086f56364712mr7146941ejb.7.1675361440001; Thu, 02 Feb 2023 10:10:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675361439; cv=none; d=google.com; s=arc-20160816; b=ngC4vmd2a2wMt8IIWK55epSCluTBYdQ9W9fnTeteQYOL+rvwzcifFwuh0SvK5KcO0l Zq34aa9sK30w1b3+I+aC533WLVKkwa87trzEoUxT5by2vnq98GMCjNtFWk8rbWZXpU5U XvrwcBQ8zm+7dhAAQ0TVgyMEhIzaXK/5Fg5C/An9Or0bQPU46BeOM4Iynt9nO80Z5h+j 9iqQeaGR+V59beQoxkaS6BAuJD1qqPHdd2Uy5+9LcXbRSwX+812wOtLZUS7ekrKvX+m1 tg7rfSk5oXl7ozuAkbWt1gnXpMVVtmkX+ocjYUQ3rbRunhN2QsKKnIfk4WyhiWrfAIt7 zUwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=kYILftIF0i8Rm9r+Yk9cPXOri/2qLIbdA2NNlKmWwwc=; b=q91KAZ09RBerj5TfNxqVhPkTYYrQHNQp40mbP+yOaQPRCTr5a+ZiMBa0SXKWy73eFF EGsCGOQhUwxyWUnx8ggxsSy2gZ9xH2VLJmzgqLPSCZt8GTGmf+jQ0G1CPKgIZ9kY1Bhd D0I9FFl9s+0Fsxdx17RLq7W23wKuPE2nRKo3cLNfPFButjP4i+GRFmiD3kgBGZg84UEv cISFqDk4JZj37olU0he558hHHOlrFveD7a397UAUaT5Zi5Utx2bVbAk1N3aWLE81ed9j V3ncyGHkjXLKacY400PnxSYNoXNP+5cIKdtH4xsh+SK+niGb2vWcfRml+HmEyArf2FrC m22g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jrDrx1cJ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id w20-20020a056402071400b004a1fe53d698si38282edx.418.2023.02.02.10.10.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:10:39 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jrDrx1cJ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C32063858418 for ; Thu, 2 Feb 2023 18:10:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C32063858418 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675361438; 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=jrDrx1cJd+Lvo0445Q2mzgzl0+scc5YGF7bUhVmn9BtqkLTrAwfrr3tW/IGW7l2RJ Y8kfHuCAi7m0RONYfOvD+nlYiQHEmcFJL/BwziRv827GOflG6CDb6MBLqOdN2cL5wf 76ld0W7hl76XhZsMwtcX7QGjmxicCPpfReIiepNw= 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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756743797533101373?= X-GMAIL-MSGID: =?utf-8?q?1756743797533101373?= 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; +}