From patchwork Thu Mar 24 00:03:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 601413 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qVmrM3FCwz9sB6 for ; Thu, 24 Mar 2016 11:04:18 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=t4/GqaJ2; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=h58EKDDjcXDn 2/0vqcas3vvdzOBbAkt93QW0YeHdBm3bfX9Q053gQ86/WWi5iByNDJ1uj2oyvIjm jfSa3+xs9FEr+IhMdg2MyH/Cuj9R9POZY7ppqTI2g6hy0OTD8oRvcbp23OBcguWp 9BRVlhllzGzbh6+CtuwM9IfNCAGxRU4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; s=default; bh=oAv6n+gsgPTtFT34lS OMutupuw0=; b=t4/GqaJ2WHRPsPB2IXHiw936kJxsGO++tHqpr1OLAJdwUj3Mc1 jeqqe7Rzzc/j3xPb3OPk/U7vKjVg6xU6r9KO2OXTYLcOahn7Fg0CIX7DqtR97KvJ JbbugyO0p3jqVPsbWYslsbdlXxEwqVJjgSqZjhnuxlEVfwgQxMYqzvXIw= Received: (qmail 44852 invoked by alias); 24 Mar 2016 00:04:09 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 44839 invoked by uid 89); 24 Mar 2016 00:04:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=1, 19 X-HELO: mail-qg0-f43.google.com Received: from mail-qg0-f43.google.com (HELO mail-qg0-f43.google.com) (209.85.192.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 24 Mar 2016 00:03:58 +0000 Received: by mail-qg0-f43.google.com with SMTP id y89so26033998qge.2 for ; Wed, 23 Mar 2016 17:03:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=xX62cCR+pgPB6e4tz54CvGaovUyp1dX07X1h39DR/9U=; b=Qn1iAWUjeV9jOHPN+PjHFZLk6JDCicVsmCkNWIVzb0y6JxXFTpQbObj/1I0WWxUuV6 0z9YD9U69JsSRliqJkNhdGG7IRsMZDLkp9gvz3L6Q/x+pmNiwjGEYS8MQ4H5faj7+3Nb e6k9VpsvaUcIdUgAlmWmXTUm8zOghiLUNFhf8T6UZrmj2lqetGTH0KsixWUsYYAiSaWN PEmmX9yZN2axllqkj4u502FYAzFa689eoYY2rnNiKppKaAvvVottrH2ByC7bdT6vDfGD WPqj9KqoQMOftVcc2HXWcLKraam2tZlsoqE4hdMah6j8j1d10EwDRkCJ3WTHtwzlnTFL ddzg== X-Gm-Message-State: AD7BkJLTBRqeSN9XWkmMMmuAaAfVowiVs1wNYNZUh1IqWtWc2jHd+iF8WcKzt/z6jlZAxw== X-Received: by 10.140.38.104 with SMTP id s95mr7068420qgs.7.1458777836433; Wed, 23 Mar 2016 17:03:56 -0700 (PDT) Received: from localhost.localdomain (ool-4353abbc.dyn.optonline.net. [67.83.171.188]) by smtp.gmail.com with ESMTPSA id x189sm2144873qhb.43.2016.03.23.17.03.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Mar 2016 17:03:55 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] Fix PR c++/62212 (ICE during mangling of array type) Date: Wed, 23 Mar 2016 20:03:50 -0400 Message-Id: <1458777830-16931-1-git-send-email-patrick@parcs.ath.cx> When mangling an ARRAY_TYPE whose element type is a typedef variant and whose domain is a type-dependent expression, we get an ICE when canonicalize_for_substitution() tries to create a canonical version of this ARRAY_TYPE with its element type being stripped of typedefs. During this canonicalization we call build_cplus_array_type which builds dependent and non-dependent array types differently. But because at this this point (during mangling) we are outside of a template decl, the function wrongly thinks that the array type being built is non-dependent according to dependent_type_p(). Because it's considered to be non-dependent we build the type with build_array_type() which tries to lay the type out and eventually we ICE because of its dependent TYPE_DOMAIN. So to fix this, the check for type-dependentness in build_cplus_array_type() should not depend on processing_template_decl. This patch makes uses_template_parms() get used instead so that it behaves properly outside of a template context, like during mangling. Does this look OK to commit after bootstrap + regtest? gcc/cp/ChangeLog: PR c++/62212 * tree.c (build_cplus_array_type): Determine type-dependentess with uses_template_parms instead of with dependent_type_p. gcc/testsuite/ChangeLog: PR c++/62212 * g++.dg/template/mangle2.C: New test. --- gcc/cp/tree.c | 5 ++--- gcc/testsuite/g++.dg/template/mangle2.C | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/mangle2.C diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index f784952..5d9de34 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -824,9 +824,8 @@ build_cplus_array_type (tree elt_type, tree index_type) if (elt_type == error_mark_node || index_type == error_mark_node) return error_mark_node; - bool dependent = (processing_template_decl - && (dependent_type_p (elt_type) - || (index_type && dependent_type_p (index_type)))); + bool dependent = (uses_template_parms (elt_type) + || (index_type && uses_template_parms (index_type))); if (elt_type != TYPE_MAIN_VARIANT (elt_type)) /* Start with an array of the TYPE_MAIN_VARIANT. */ diff --git a/gcc/testsuite/g++.dg/template/mangle2.C b/gcc/testsuite/g++.dg/template/mangle2.C new file mode 100644 index 0000000..50b0d9f --- /dev/null +++ b/gcc/testsuite/g++.dg/template/mangle2.C @@ -0,0 +1,19 @@ +// PR c++/62212 +// { dg-do assemble } + +typedef int my_int; + +template +struct X { + enum {value = 1}; +}; + +template +void f(const my_int(&)[X::value]); + +int main() { + const my_int a[1] = {}; + f(a); +} + +// { dg-final { scan-assembler "_Z1fIvEvRAsr1XIT_E5value_Ki" } }