From patchwork Mon Dec 12 19:12:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 87732 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1811706qgi; Mon, 12 Dec 2016 11:12:41 -0800 (PST) X-Received: by 10.99.105.70 with SMTP id e67mr164925867pgc.99.1481569961851; Mon, 12 Dec 2016 11:12:41 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id j63si44659975pfg.51.2016.12.12.11.12.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Dec 2016 11:12:41 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-444207-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-444207-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-444207-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=hOwNNbfuc9Ar+K/jOKNcFFolUx8WCvAElsz1iv4vhmRIEf+0sn H0ZdRQbvv0BzNvYkDI+B65xg6nhAnd+cXpQQtzWJEACY2BQIVMULg3JWk/maBnX4 OSjH0eJDAMEeSVbIv/HLuqkO+7cnKZLC/S8KFE5Oe1ORQAo89qfSHcwjQ= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=k534zRAIGcUp8uQrHWBQonz7iPM=; b=PXNtHMnMjdbqbW3wrScu x5swYqAx0Pc4m6HW1dRWeorDC995APdfoMoOlEtVGKzICXzRehA8zvzwAM/OH2Jn AQ1nKb2ghzOVGeyqRd92TF2H/hW1dTLfzc2Be2n3aJ9iI6XjiLnvhG67zPu1JNvB mYc5e8lzNcmXoW2cat5YY18= Received: (qmail 119717 invoked by alias); 12 Dec 2016 19:12:25 -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 119698 invoked by uid 89); 12 Dec 2016 19:12:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=sk:decl_la, sk:DECL_LA, H*MI:b1e2 X-HELO: mail-yw0-f195.google.com Received: from mail-yw0-f195.google.com (HELO mail-yw0-f195.google.com) (209.85.161.195) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 12 Dec 2016 19:12:14 +0000 Received: by mail-yw0-f195.google.com with SMTP id a10so8504745ywa.1 for ; Mon, 12 Dec 2016 11:12:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:to:cc:from:subject:message-id:date :user-agent:mime-version; bh=UCOdwftvTNAVL3QmEz1Qrk4/fIoWYfs7h7VRiKG0s/o=; b=GXwt/CI6zRtN1EezLq/wSg6v+taZJGasF35llAGniND0wZlO+IO58TbORnmYKZprWk zj8kMyI+hdofzfHCYavIgew/yAJoiVzZEpIA7BYLK2iyCQdE7bu0nphAtkw5+Ajbr9tc DuQrMAZLZvck937DWt4XRHVx4rbFtuPSu0WHE2S9R52IZ15qLxM43vEDLAB2CGP4tOdc zTAP99wW9xzx69XnhXYUN9ScKkF+lLMyoBo2w3ooS2Hjy4UF9oJJsxrynYOvI9bpjXhm QR40HqwJatSKv3VFh1VLnzaN2iN8m34Q71bWKCYK/Zvge7FkkFA9SPr+bmpnra/vq629 Mi9g== X-Gm-Message-State: AKaTC02Qey3SVEyYBX3GsVHIy6TgAA+DdY6BlP5yFor8PjuLQiOktqkZNi3eWBcgKUhuDw== X-Received: by 10.129.78.142 with SMTP id c136mr88077932ywb.172.1481569933175; Mon, 12 Dec 2016 11:12:13 -0800 (PST) Received: from ?IPv6:2620:10d:c0a3:20fb:f6d0:5ac5:64cd:f102? ([2620:10d:c091:200::640]) by smtp.googlemail.com with ESMTPSA id v137sm18513441ywa.30.2016.12.12.11.12.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Dec 2016 11:12:12 -0800 (PST) To: Jason Merrill Cc: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] c++/78776 fix alias template ICE Message-ID: Date: Mon, 12 Dec 2016 14:12:11 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 This patch fixes an ICE in a checking build where structural_comptypes disagrees with TYPE_CANONICAL. An (implicit) template alias has a different TYPE_TI_TEMPLATE to the thing its aliasing. That make structural comparison think it's different. In the testcase we end up thinking 'Loc' refers to a different template than 'Traits' Solved by breaking TYPE_TEMPLATE_INFO into an underlying helper that doesn't deal with type aliases. While there, I noticed TYPE_TEMPLATE_INFO was doing more work than necessary because it checked twice whether DECL_LANG_SPECIFIC (TYPE_NAME (NODE)) was non-null. There's no need to check it again in the branch we can only get to when it's non-null. I also removed some unnecessary parens. ok? nathan -- Nathan Sidwell 2016-12-12 Nathan Sidwell PR c++/78776 * cp-tree.h (TYPE_TEMPLATE_INFO_RAW): New, broken out of ... (TYPE_TEMPLATE_INFO): ... here. Use it. * typeck.c (structural_comptypes): Adjust record/union check to avoid alias template confusion. PR c++/78776 * g++.dg/cpp0x/pr78776.C: New. Index: cp/cp-tree.h =================================================================== --- cp/cp-tree.h (revision 243554) +++ cp/cp-tree.h (working copy) @@ -3038,22 +3038,25 @@ extern void decl_shadowed_for_var_insert ->template_info) /* Template information for an ENUMERAL_, RECORD_, UNION_TYPE, or - BOUND_TEMPLATE_TEMPLATE_PARM type. Note that if NODE is a - specialization of an alias template, this accessor returns the - template info for the alias template, not the one (if any) for the - template of the underlying type. */ + BOUND_TEMPLATE_TEMPLATE_PARM type. This ignores any alias + templateness of NODE. */ + +#define TYPE_TEMPLATE_INFO_RAW(NODE) \ + (TREE_CODE (NODE) == ENUMERAL_TYPE \ + ? ENUM_TEMPLATE_INFO (NODE) \ + : (TREE_CODE (NODE) == BOUND_TEMPLATE_TEMPLATE_PARM \ + ? TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (NODE) \ + : (CLASS_TYPE_P (NODE) \ + ? CLASSTYPE_TEMPLATE_INFO (NODE) \ + : NULL_TREE))) + +/* If NODE is a specialization of an alias template, this accessor + returns the template info for the alias template. Otherwise behave + as TYPE_TEMPLATE_INFO_RAW. */ #define TYPE_TEMPLATE_INFO(NODE) \ - ((TYPE_ALIAS_P (NODE) && DECL_LANG_SPECIFIC (TYPE_NAME (NODE))) \ - ? (DECL_LANG_SPECIFIC (TYPE_NAME (NODE)) \ - ? DECL_TEMPLATE_INFO (TYPE_NAME (NODE)) \ - : NULL_TREE) \ - : ((TREE_CODE (NODE) == ENUMERAL_TYPE) \ - ? ENUM_TEMPLATE_INFO (NODE) \ - : ((TREE_CODE (NODE) == BOUND_TEMPLATE_TEMPLATE_PARM) \ - ? TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (NODE) \ - : (CLASS_TYPE_P (NODE) \ - ? CLASSTYPE_TEMPLATE_INFO (NODE) \ - : NULL_TREE)))) + (TYPE_ALIAS_P (NODE) && DECL_LANG_SPECIFIC (TYPE_NAME (NODE)) \ + ? DECL_TEMPLATE_INFO (TYPE_NAME (NODE)) \ + : TYPE_TEMPLATE_INFO_RAW (NODE)) /* Set the template information for an ENUMERAL_, RECORD_, or Index: cp/typeck.c =================================================================== --- cp/typeck.c (revision 243554) +++ cp/typeck.c (working copy) @@ -1284,18 +1284,23 @@ structural_comptypes (tree t1, tree t2, case RECORD_TYPE: case UNION_TYPE: - if (TYPE_TEMPLATE_INFO (t1) && TYPE_TEMPLATE_INFO (t2) - && (TYPE_TI_TEMPLATE (t1) == TYPE_TI_TEMPLATE (t2) - || TREE_CODE (t1) == BOUND_TEMPLATE_TEMPLATE_PARM) - && comp_template_args (TYPE_TI_ARGS (t1), TYPE_TI_ARGS (t2))) - break; + { + /* Ignore any alias templateness. */ + tree ti1 = TYPE_TEMPLATE_INFO_RAW (t1); + tree ti2 = TYPE_TEMPLATE_INFO_RAW (t2); - if ((strict & COMPARE_BASE) && DERIVED_FROM_P (t1, t2)) - break; - else if ((strict & COMPARE_DERIVED) && DERIVED_FROM_P (t2, t1)) - break; + if (ti1 && ti2 + && (TI_TEMPLATE (ti1) == TI_TEMPLATE (ti2) + || TREE_CODE (t1) == BOUND_TEMPLATE_TEMPLATE_PARM) + && comp_template_args (TI_ARGS (ti1), TI_ARGS (ti2))) + break; + if ((strict & COMPARE_BASE) && DERIVED_FROM_P (t1, t2)) + break; + else if ((strict & COMPARE_DERIVED) && DERIVED_FROM_P (t2, t1)) + break; - return false; + return false; + } case OFFSET_TYPE: if (!comptypes (TYPE_OFFSET_BASETYPE (t1), TYPE_OFFSET_BASETYPE (t2), Index: testsuite/g++.dg/cpp0x/pr78776.C =================================================================== --- testsuite/g++.dg/cpp0x/pr78776.C (revision 0) +++ testsuite/g++.dg/cpp0x/pr78776.C (working copy) @@ -0,0 +1,15 @@ +// PR c++/78776 +// { dg-do compile { target c++11 } } + +// ICE with canonical type verification + +template struct Traits; + +template +struct Bob { + using Loc = Traits; + using typename Loc::Thing; + + Thing Foo (); +}; +