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 [216.205.24.74]) by sourceware.org (Postfix) with ESMTP id D73C7385C426 for ; Mon, 23 Mar 2020 01:21:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D73C7385C426 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-427-aw86H0qKNI-fPaIJ-iSVkw-1; Sun, 22 Mar 2020 21:21:12 -0400 X-MC-Unique: aw86H0qKNI-fPaIJ-iSVkw-1 Received: by mail-qt1-f200.google.com with SMTP id l29so11841518qtu.11 for ; Sun, 22 Mar 2020 18:21:12 -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:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=BKo3RbTjDeL7FQVsicTjCrMS/QKnljPo+oel569CmiQ=; b=ZpcUQT03K727gUhYEEcJHmzlsMV9aj5gwuV8A/JKTauZRSQg1B4Lte/MZ+PcMd9628 cn6KE6MvSgsACxDjXfNfOgpJvX9c9tnFCgFKW5oWKBTwtX/AcA/AeJNLICmWiSG1FZdP J1jCglbO1RF531RRoARtCkPjsivbAviwXJ1gos/5q6M67pBZZpZbuIxYGLNGJPsilf9T vGx/oZCjYkYItcSVtEyLRf4W8XIMu2lEdQEs/CXHsu4DCXFrBtjfPOe5hPnKtlOk/+fX 4+Jh+7PudwRNOKvduGRvd72spa+DMNo6upXat7aDH7oypjv0Y1jRCskEkvMlcbCijGnN pU1A== X-Gm-Message-State: ANhLgQ0FXQlrZvJ0e+KSc2OCLZ6zEevykWOMwGbaalRvwjxoyIo1nbt+ XC3rTHZHINz7vIEybyF5Fyabw0Bb8Y041ZzuyQOmc42EpEsmQillOn1yqtSqzpdJsaT7vCvCI4g dMmPQV5WHm4UqkulwJQ== X-Received: by 2002:a37:4b97:: with SMTP id y145mr19546428qka.167.1584926471552; Sun, 22 Mar 2020 18:21:11 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuc7Goz6oglc4VZ1/zA48dFXEAteBUAlJqMipjs5B5PLIBWjQ/q7xuhsDQcyCuLUskqmCc4mg== X-Received: by 2002:a37:4b97:: with SMTP id y145mr19546411qka.167.1584926471204; Sun, 22 Mar 2020 18:21:11 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id t53sm11088190qth.70.2020.03.22.18.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Mar 2020 18:21:10 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Fix ICE in tsubst_default_argument [PR92010] Date: Sun, 22 Mar 2020 21:21:05 -0400 Message-Id: <20200323012105.3692086-1-ppalka@redhat.com> X-Mailer: git-send-email 2.26.0.rc1.11.g30e9940356 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.3 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 01:21:17 -0000 This patch relaxes an assertion in tsubst_default_argument that exposes a l= atent bug in how we substitute an array type into a cv-qualified wildcard functio= n parameter type. Concretely, the latent bug is that given the function temp= late template void foo(const T t); 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 end = up obtaining void(int*) as the type of foo after substitution and decay= ing. We still however correctly substitute into and decay the formal parameter t= ype, obtaining const int* as the type of t after substitution. But this then le= ads to us tripping over the assert in tsubst_default_argument that verifies the formal parameter type and the function type are consistent. Assuming it's too late at this stage to fix the substitution bug, we can st= ill relax the assertion like so. Tested on x86_64-pc-linux-gnu, does this look= OK? gcc/cp/ChangeLog: =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. gcc/testsuite/ChangeLog: =09PR c++/92010 =09* g++.dg/template/defarg22.C: New test. --- gcc/cp/pt.c | 17 ++++++++++++++++- gcc/testsuite/g++.dg/template/defarg22.C | 11 +++++++++++ 2 files changed, 27 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 9e1eb9416c9..923166276b8 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -13337,7 +13337,22 @@ 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 if (POINTER_TYPE_P (type) && POINTER_TYPE_P (parmtype)) + { + /* The function type and the parameter type can disagree about the +=09 cv-qualification of the pointed-to type; see PR92010. */ + gcc_assert (same_type_p (TREE_TYPE (type), +=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))); + } + else + gcc_unreachable (); =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