From patchwork Mon Mar 23 01:21:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 1259803 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=uwCkd5Jg; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48lxRX11XSz9sQt for ; Mon, 23 Mar 2020 12:21:26 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2D557385E000; Mon, 23 Mar 2020 01:21:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D557385E000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1584926479; bh=bWP5aQEbAEhVhPhF2mAxBp7580rVV1qOvNqVwW5Ulm0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=uwCkd5JgcfI0v/EHnJkULsJxf/RSqzPR5yq2xyCjKR1waiysNGrPaFBviDFAPo/Zn 4Ay6uGpy0QE1CnJpikUbktyaibiCZLUCsmSZ1ObFjlhwCNcMp0Rur1kWueAhx7u7Jr Mh0v2kEOchJObW10eON7IJY+71m4CYKR+v3XOGU0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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) 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 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-Patchwork-Original-From: Patrick Palka via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: Patrick Palka Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" 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 function parameter type. Concretely, the latent bug is that given the function template 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 decaying. 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 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 still relax the assertion like so. Tested on x86_64-pc-linux-gnu, does this look OK? gcc/cp/ChangeLog: PR c++/92010 * pt.c (tsubst_default_argument): Relax assertion to permit disagreements between the function type and the parameter type about the cv-qualification of the pointed-to type. gcc/testsuite/ChangeLog: PR c++/92010 * 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, tree type, tree arg, if (parmtype == error_mark_node) return error_mark_node; - 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 + cv-qualification of the pointed-to type; see PR92010. */ + gcc_assert (same_type_p (TREE_TYPE (type), + strip_top_quals (TREE_TYPE (parmtype)))); + /* Verify that this happens only when the dependent parameter type is a + cv-qualified wildcard type. */ + tree pattern_parm = get_pattern_parm (parm, DECL_TI_TEMPLATE (fn)); + gcc_assert (WILDCARD_TYPE_P (TREE_TYPE (pattern_parm)) + && cv_qualified_p (TREE_TYPE (pattern_parm))); + } + else + gcc_unreachable (); tree *slot; if (defarg_inst && (slot = defarg_inst->get (parm))) diff --git a/gcc/testsuite/g++.dg/template/defarg22.C b/gcc/testsuite/g++.dg/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 = 0) +{ } + +int main() +{ + foo(); +}