From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 721603858C52 for ; Thu, 2 Feb 2023 21:26:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 721603858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675373197; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=17Klvpn87l5ne1yshul1Mh3c5tPV5TGL6uWgV4agA1M=; b=X67S+pfmrX3JINBRYP/M7+j7Il3k/IRqU2gnHyWKqlJp2Iz+A89aEVHHX48rmC5VCjOxu3 2j6XkJ9W1+Pf61gwxUGlGghhE2fEnVW5aGe/wiRQyVONjNFs3gFGzc6MdOxDIB1eTADD+z cu5juLJ2sJMSlqhCruPpLipKD9SG5a0= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-501-1fJQShl9MGG5oxhqPYgOog-1; Thu, 02 Feb 2023 16:26:35 -0500 X-MC-Unique: 1fJQShl9MGG5oxhqPYgOog-1 Received: by mail-qk1-f200.google.com with SMTP id g6-20020ae9e106000000b00720f9e6e3e2so2128650qkm.13 for ; Thu, 02 Feb 2023 13:26:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=17Klvpn87l5ne1yshul1Mh3c5tPV5TGL6uWgV4agA1M=; b=RtHsV5W84+ntNLloSankUGJse7ByPkSjde2P9JJGCTg8fWhFipbEtkf7dyqd53GxEb K5Bdx/UMGfU/xFDpg8w7AQtQSU19HeW3Lyw3TCu0YaZn6V96vtVLWXrjNGgIC4nWdl2C SWPz/ApyNR+3tlQbqYeAimsiKKGR6Rg1o9INGbQXAeZeebQS/x5mQyJX3G/dktldIhMS 6WjrtdT6XrLXv7XwiCITS6KW1Fzb4I8b6uBGm/fYyj5xQa0lJTMet5HctumXQd4pygoh 2vWF2sccSNwvnahzC5vG8AMjPLJOA1zmLTK0RnP3js+cFO4aZF0N6yOBoKIBt/DNsfwj Y1CQ== X-Gm-Message-State: AO0yUKWjwUeQb8vR154AJf76KI7vArv+7OKOKzUIrl09cWUg1Oo2q0XB y2qprv8Q2irJIRZkV84qBssOA+syZnWkwQckw5bV7fUqiV1DPZmFMxiyqsbmrbHNZxfmlujeavd 4OPsgn02d+In2IFytsQ== X-Received: by 2002:a0c:e410:0:b0:538:141e:f6a6 with SMTP id o16-20020a0ce410000000b00538141ef6a6mr12462586qvl.36.1675373195259; Thu, 02 Feb 2023 13:26:35 -0800 (PST) X-Google-Smtp-Source: AK7set/G2MoGFdayR0A6nL4Mv8dX5Fs+6g7qlDsbr2PdnCGbddx80NhqMDmkYQpUhXB8mD2vrYlLUQ== X-Received: by 2002:a0c:e410:0:b0:538:141e:f6a6 with SMTP id o16-20020a0ce410000000b00538141ef6a6mr12462557qvl.36.1675373194906; Thu, 02 Feb 2023 13:26:34 -0800 (PST) Received: from [192.168.1.108] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id j24-20020a37ef18000000b0072396cb73cdsm510565qkk.13.2023.02.02.13.26.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 02 Feb 2023 13:26:34 -0800 (PST) Message-ID: <410c789a-b13d-5660-d6ab-c58505deb953@redhat.com> Date: Thu, 2 Feb 2023 16:26:33 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH] c++: spurious ADDR_EXPR after overload set pruning [PR107461] To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20230202180950.3469931-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20230202180950.3469931-1-ppalka@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,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 List-Id: On 2/2/23 13:09, Patrick Palka wrote: > 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? OK. As a future direction, I'd think we want to do the same pruning for other forms of "FN". Jason > 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; > +}