From patchwork Thu May 21 22:20:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 475240 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 2761014077A for ; Fri, 22 May 2015 08:20:51 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=OmZxj0xp; 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 :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=KhayhpN6PccGpnKTu12H8sQB1YfLOMC+q1fleejyLEP pW23YSDgcMPwFgl5QHDJ1hBIbnE1tjbmoD1ts10h2h6uibI2OhuqOm78yPRiUb6T 0Bb0mrA8Y2rRVjry6zpUviFT/Uvut5t0q3NF6sSweilja0520SAVsVF7o0u77qJQ = 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 :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=VSnLgq9fAIUJrNajOL38FzU7ICw=; b=OmZxj0xpa2aZ7Wn5s Xvmyq5U/d2kgWeuXrL3fsVVaEDOslVPoOVqjCbSeVEqUcVOtn2Elg3LtLHnNcBys nGYGXul55EJbVu2OgBg5eppygrEnlQF/GzQC0id3MZFHe4ac93+VbkKRdBb3Bz81 9IFigS0MC4wtElPdsyk37JdNqs= Received: (qmail 42020 invoked by alias); 21 May 2015 22:20:44 -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 42005 invoked by uid 89); 21 May 2015 22:20:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-qc0-f182.google.com Received: from mail-qc0-f182.google.com (HELO mail-qc0-f182.google.com) (209.85.216.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 21 May 2015 22:20:42 +0000 Received: by qctt3 with SMTP id t3so660972qct.1 for ; Thu, 21 May 2015 15:20:40 -0700 (PDT) X-Received: by 10.140.21.134 with SMTP id 6mr6942770qgl.47.1432246840526; Thu, 21 May 2015 15:20:40 -0700 (PDT) Received: from ?IPv6:2601:6:8380:343:a2a8:cdff:fe3e:b48? ([2601:6:8380:343:a2a8:cdff:fe3e:b48]) by mx.google.com with ESMTPSA id g92sm135102qgf.20.2015.05.21.15.20.38 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 May 2015 15:20:39 -0700 (PDT) Message-ID: <555E5A35.9050306@acm.org> Date: Thu, 21 May 2015 18:20:37 -0400 From: Nathan Sidwell User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Jason Merrill CC: GCC Patches Subject: [C++ PATCH] fix canonical type ICE Jason, this fixes 65936, where we have two identical types with mismatching TYPE_CANONICAL. The problem comes from template decl creation vs template instantiation. At the point we create 'const C' in the operator function we have not applied the 'may_alias' attribute to 'const C'. This means that the following snippet in tree.c:7729 build_pointer_type_for_mode if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type))) can_alias_all = true; doesn't set 'can_alias_all'. Later we complete C and parse the static_cast in the operator function. Completing C will have applied the may_alias attribute. So this time can_alias_all gets set on pointers to C variants. This leads to two different pointer types differing by TYPE_REF_CAN_ALIAS_ALL, each having different CANONICAL_TYPEs. However as TYPE_STRUCTURAL_EQUALITY_P is false, we have a problem. We blow up in comptypes verifying the canonical type machinery. This patch applies the may_alias attribute to the instantiated decl. built & tested on x86_64-linux, ok? nathan 2015-05-21 Nathan Sidwell cp/ PR c++/65936 pt.c (lookup_template_class_1): Apply may_alias attribute here. testsuite/ * g++.dg/template/pr65936.C: New. Index: cp/pt.c =================================================================== --- cp/pt.c (revision 223503) +++ cp/pt.c (working copy) @@ -7856,6 +7856,10 @@ lookup_template_class_1 (tree d1, tree a = CLASSTYPE_DECLARED_CLASS (template_type); SET_CLASSTYPE_IMPLICIT_INSTANTIATION (t); TYPE_FOR_JAVA (t) = TYPE_FOR_JAVA (template_type); + if (lookup_attribute ("may_alias", + TYPE_ATTRIBUTES (template_type))) + TYPE_ATTRIBUTES (t) = tree_cons (get_identifier ("may_alias"), + NULL_TREE, NULL_TREE); /* A local class. Make sure the decl gets registered properly. */ if (context == current_function_decl) Index: testsuite/g++.dg/template/pr65936.C =================================================================== --- testsuite/g++.dg/template/pr65936.C (revision 0) +++ testsuite/g++.dg/template/pr65936.C (working copy) @@ -0,0 +1,21 @@ +// checking ICE in canonical typing + +class A; + +template struct B +{ + typedef A type; +}; + +template class C + : public B::type +{ +} __attribute__ ((__may_alias__)); + +class A +{ + operator const C &() + { + return *static_cast *> (this); + } +};