From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by sourceware.org (Postfix) with ESMTP id 61FC1385B831 for ; Mon, 23 Mar 2020 03:11:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 61FC1385B831 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-312-ctOdcg6oPMWgL3ec6dsAeg-1; Sun, 22 Mar 2020 23:11:08 -0400 X-MC-Unique: ctOdcg6oPMWgL3ec6dsAeg-1 Received: by mail-qk1-f197.google.com with SMTP id w124so11468531qkd.19 for ; Sun, 22 Mar 2020 20:11:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=G6Heq9OU8IDJ7ms02FoWAMsk9E/GW+p+C3KS225VVKM=; b=kgp3bi/GSox8Z5rePbvnrBxsYv2bPAVrliEWnP90kv5Op3rz0jpiJdUCBLSyO/isAB vqwBXAw5yhtR6QyfpJrsYp2v7NuTYIo4SxWYrzA4DNJ+sJA9J9qWqPh8qHjxc/8LF2d1 Oja5Z1s8qvNAJeoiTJM6Cgt6e80/bdeILSSNyytSsdW020p64PPr3T3KyjV/A8hOmj2q zHgwmNIR9X/t6wzSygaCN2NTNOM/oEb4SVmWhJxF60HHBL2GKO/rvq462Py4RHIICsHT +Hm2kZABwa69UUPgPSCbxUHmXF+PlBPeC62zp7Z/Ol4Ac1MUM7C32vsd3l1ByUEeRkOK obWQ== X-Gm-Message-State: ANhLgQ0I0inHz+rgPiMHsM66IME41iTJS9ZeilSSQRV9j6wrHZyL21Xm KG1xKS4Q5K5URwAVJ8FA+F4VrgMWQqJUAaoq+JvcEnVi/ZRb47e+d6CwmGppJuPCIpIFTZR8dBw hEfMIySbv7Ys2WRBO/w== X-Received: by 2002:aed:3241:: with SMTP id y59mr18646674qtd.351.1584933067840; Sun, 22 Mar 2020 20:11:07 -0700 (PDT) X-Google-Smtp-Source: ADFU+vu8t/brgrlotBb2h0RxpZ4DNlwE5LOBGrFMQOPbFpLutYpMt5asLeWEsQLUCT0kPDijRp0ZzA== X-Received: by 2002:aed:3241:: with SMTP id y59mr18646654qtd.351.1584933067525; Sun, 22 Mar 2020 20:11:07 -0700 (PDT) Received: from [192.168.1.130] (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id h46sm1655152qtc.84.2020.03.22.20.11.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Mar 2020 20:11:06 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Sun, 22 Mar 2020 23:11:06 -0400 (EDT) To: Patrick Palka cc: gcc-patches@gcc.gnu.org, jason@redhat.com Subject: Re: [PATCH] c++: Fix ICE in tsubst_default_argument [PR92010] In-Reply-To: <20200323012105.3692086-1-ppalka@redhat.com> Message-ID: References: <20200323012105.3692086-1-ppalka@redhat.com> User-Agent: Alpine 2.22 (DEB 413 2020-03-19) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-34.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Mon, 23 Mar 2020 03:11:12 -0000 On Sun, 22 Mar 2020, Patrick Palka wrote: > This patch relaxes an assertion in tsubst_default_argument that exposes a= latent > bug in how we substitute an array type into a cv-qualified wildcard funct= ion > parameter type. Concretely, the latent bug is that given the function te= mplate >=20 > template void foo(const T t); >=20 > one would expect the type of foo to be void(const int*), but we > (seemingly prematurely) strip function parameter types of their top-level > cv-qualifiers when building the function's TYPE_ARG_TYPES, and instead en= d up > obtaining void(int*) as the type of foo after substitution and dec= aying. >=20 > We still however correctly substitute into and decay the formal parameter= type, > obtaining const int* as the type of t after substitution. But this then = leads > to us tripping over the assert in tsubst_default_argument that verifies t= he > formal parameter type and the function type are consistent. >=20 > Assuming it's too late at this stage to fix the substitution bug, we can = still > relax the assertion like so. Tested on x86_64-pc-linux-gnu, does this lo= ok OK? >=20 > gcc/cp/ChangeLog: >=20 > =09PR c++/92010 > =09* pt.c (tsubst_default_argument): Relax assertion to permit > =09disagreements between the function type and the parameter type > =09about the cv-qualification of the pointed-to type. >=20 > gcc/testsuite/ChangeLog: >=20 > =09PR c++/92010 > =09* g++.dg/template/defarg22.C: New test. > --- Here's a slightly simpler version of the patch that moves the POINTER_TYPE_P checks into the gcc_assert: -- >8 -- --- gcc/cp/pt.c | 16 +++++++++++++++- gcc/testsuite/g++.dg/template/defarg22.C | 11 +++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/template/defarg22.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 03a8dfbd37c..849628840d6 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -13337,7 +13337,21 @@ tsubst_default_argument (tree fn, int parmnum, tre= e type, tree arg, if (parmtype =3D=3D error_mark_node) return error_mark_node; =20 - gcc_assert (same_type_ignoring_top_level_qualifiers_p (type, parmtype)); + if (same_type_ignoring_top_level_qualifiers_p (type, parmtype)) + ; + else + { + /* The function type and the parameter type can disagree about the +=09 cv-qualification of the pointed-to type; see PR92010. */ + gcc_assert (POINTER_TYPE_P (type) && POINTER_TYPE_P (parmtype) +=09=09 && same_type_p (TREE_TYPE (type), +=09=09=09=09 strip_top_quals (TREE_TYPE (parmtype)))); + /* Verify that this happens only when the dependent parameter type i= s a +=09 cv-qualified wildcard type. */ + tree pattern_parm =3D get_pattern_parm (parm, DECL_TI_TEMPLATE (fn))= ; + gcc_assert (WILDCARD_TYPE_P (TREE_TYPE (pattern_parm)) +=09=09 && cv_qualified_p (TREE_TYPE (pattern_parm))); + } =20 tree *slot; if (defarg_inst && (slot =3D defarg_inst->get (parm))) diff --git a/gcc/testsuite/g++.dg/template/defarg22.C b/gcc/testsuite/g++.d= g/template/defarg22.C new file mode 100644 index 00000000000..cf6261916d8 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/defarg22.C @@ -0,0 +1,11 @@ +// PR c++/92010 +// { dg-do compile } + +template +void foo(const T t =3D 0) +{ } + +int main() +{ + foo(); +} --=20 2.26.0.rc1.11.g30e9940356