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 0714F3858C27 for ; Fri, 11 Mar 2022 23:42:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0714F3858C27 Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-633-zRK5Sw_zMtCdhqIbya2naQ-1; Fri, 11 Mar 2022 18:42:28 -0500 X-MC-Unique: zRK5Sw_zMtCdhqIbya2naQ-1 Received: by mail-oi1-f198.google.com with SMTP id w19-20020a0568080d5300b002d54499cc1eso7121165oik.19 for ; Fri, 11 Mar 2022 15:42:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=+HCqNNM7u62Ly5nRQlUFcs8PX1y2oyyhvpmaSt127bw=; b=DfTrZfSqkiSAuV2Zc65tyRSRZXNWjk8S/Za17s7mMZ2jRYpPI+Nc1YUeMjA3jcD4rr CWtqMHvXec7jq/cq3H7jIBhWSfyQ72xgie8LP+8LZEUUNSnlYXa5tahOpZ8z2H8ypbIv mBKEnFdoz9xUudQmnUQPahQC5q+JkESfl4CctEjQ/OrMOf+N9DB+WVU3K6/YPDrfKzhI i/3VdhHV0ffd9SJokOETwcCWGBwU32nAg2lyNl1+fDPMxeTp6qrkVFOgOzgYH9zQdb/5 MOwoI9CDGb6oGbQF12V+BrOADKD2ghVNh1ls1XR3WsRnr56ifOBH9opOhhow8tBOwxNX Pd+w== X-Gm-Message-State: AOAM533LuKsn/Ihlps8rxunnkqXTh1VF/Y7DKi3YKqS0YOmKtmWytOgz LVNoj8oK0+2zABKC8AMNnmvbFvaN+f/Xsc/yy35m2Pd720iISwP7SEJJEuf3jPi8erYIyW8MOaP r+rxPQgVzfjaRXwxUYg== X-Received: by 2002:a05:6870:e415:b0:d9:8013:205c with SMTP id n21-20020a056870e41500b000d98013205cmr12221135oag.60.1647042147458; Fri, 11 Mar 2022 15:42:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJwkNctwnP1Htr9y4osQNQ1DX1QnHjgfnM29c8/ItosRNpz6oIVc7TYCVIfl2kJALJA/sYFKjg== X-Received: by 2002:a05:6870:e415:b0:d9:8013:205c with SMTP id n21-20020a056870e41500b000d98013205cmr12221115oag.60.1647042147059; Fri, 11 Mar 2022 15:42:27 -0800 (PST) Received: from [192.168.1.149] (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 v24-20020a9d5a18000000b005ad458facbdsm4321319oth.27.2022.03.11.15.42.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 11 Mar 2022 15:42:26 -0800 (PST) Message-ID: Date: Fri, 11 Mar 2022 18:42:20 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [PATCH] c++: Fix ICE with bad conversion shortcutting [PR104622] To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20220310193047.1781920-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20220310193047.1781920-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.8 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, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Fri, 11 Mar 2022 23:42:33 -0000 On 3/10/22 15:30, Patrick Palka wrote: > When shortcutting bad conversions during overload resolution, we assume > argument conversions get computed in sequential order and that therefore > we just need to inspect the last conversion in order to determine if _any_ > conversion is missing. But this assumption turns out to be false for > templates, because during deduction check_non_deducible_conversion can > compute an argument conversion out of order. > > So in the testcase below, at the end of add_template_candidate the convs > array looks like {bad, missing, good} where the last conversion was > computed during deduction and the first was computed later from > add_function_candidate. We need to add this candidate to BAD_FNS since > not all of its argument conversions were computed, but we don't do so > because we only checked if the last argument conversion was missing. > > This patch fixes this by checking for a missing conversion exhaustively. > In passing, this cleans up check_non_deducible_conversion a bit since > AFAICT the only values of strict we expect to see here are the three > enumerators of unification_kind_t. > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk? OK. > PR c++/104622 > > gcc/cp/ChangeLog: > > * call.cc (missing_conversion_p): Define. > (add_candidates): Use it. > * pt.cc (check_non_deducible_conversion): Change type of strict > parameter to unification_kind_t and directly test for DEDUCE_CALL. > > gcc/testsuite/ChangeLog: > > * g++.dg/template/conv18.C: New test. > --- > gcc/cp/call.cc | 13 ++++++++++++- > gcc/cp/pt.cc | 6 +++--- > gcc/testsuite/g++.dg/template/conv18.C | 14 ++++++++++++++ > 3 files changed, 29 insertions(+), 4 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/template/conv18.C > > diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc > index d6eed5ed835..8fe8ef306ea 100644 > --- a/gcc/cp/call.cc > +++ b/gcc/cp/call.cc > @@ -6023,6 +6023,17 @@ perfect_candidate_p (z_candidate *cand) > return true; > } > > +/* True iff one of CAND's argument conversions is NULL. */ > + > +static bool > +missing_conversion_p (const z_candidate *cand) > +{ > + for (unsigned i = 0; i < cand->num_convs; ++i) > + if (!cand->convs[i]) > + return true; > + return false; > +} > + > /* Add each of the viable functions in FNS (a FUNCTION_DECL or > OVERLOAD) to the CANDIDATES, returning an updated list of > CANDIDATES. The ARGS are the arguments provided to the call; > @@ -6200,7 +6211,7 @@ add_candidates (tree fns, tree first_arg, const vec *args, > > if (cand->viable == -1 > && shortcut_bad_convs > - && !cand->convs[cand->reversed () ? 0 : cand->num_convs - 1]) > + && missing_conversion_p (cand)) > { > /* This candidate has been tentatively marked non-strictly viable, > and we didn't compute all argument conversions for it (having > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index f890d92d715..715eea27577 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -152,7 +152,7 @@ static tree coerce_innermost_template_parms (tree, tree, tree, tsubst_flags_t, > bool, bool); > static void tsubst_enum (tree, tree, tree); > static bool check_instantiated_args (tree, tree, tsubst_flags_t); > -static int check_non_deducible_conversion (tree, tree, int, int, > +static int check_non_deducible_conversion (tree, tree, unification_kind_t, int, > struct conversion **, bool); > static int maybe_adjust_types_for_deduction (tree, unification_kind_t, > tree*, tree*, tree); > @@ -22304,7 +22304,7 @@ maybe_adjust_types_for_deduction (tree tparms, > unify_one_argument. */ > > static int > -check_non_deducible_conversion (tree parm, tree arg, int strict, > +check_non_deducible_conversion (tree parm, tree arg, unification_kind_t strict, > int flags, struct conversion **conv_p, > bool explain_p) > { > @@ -22324,7 +22324,7 @@ check_non_deducible_conversion (tree parm, tree arg, int strict, > if (can_convert_arg (type, parm, NULL_TREE, flags, complain)) > return unify_success (explain_p); > } > - else if (strict != DEDUCE_EXACT) > + else if (strict == DEDUCE_CALL) > { > bool ok = false; > tree conv_arg = TYPE_P (arg) ? NULL_TREE : arg; > diff --git a/gcc/testsuite/g++.dg/template/conv18.C b/gcc/testsuite/g++.dg/template/conv18.C > new file mode 100644 > index 00000000000..f59f6fda77c > --- /dev/null > +++ b/gcc/testsuite/g++.dg/template/conv18.C > @@ -0,0 +1,14 @@ > +// PR c++/104622 > +// { dg-additional-options "-fpermissive" } > + > +template > +struct type_identity { > + typedef T type; > +}; > + > +template void f(typename type_identity::type*, T, int*); > + > +int main() { > + const int p = 0; > + f(&p, 0, 0); // { dg-warning "invalid conversion" } > +}