From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 61492 invoked by alias); 14 Jan 2020 19:14:36 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 61483 invoked by uid 89); 14 Jan 2020 19:14:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=H*r:10d X-HELO: mail-qk1-f181.google.com Received: from mail-qk1-f181.google.com (HELO mail-qk1-f181.google.com) (209.85.222.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 14 Jan 2020 19:14:26 +0000 Received: by mail-qk1-f181.google.com with SMTP id z76so13240815qka.2 for ; Tue, 14 Jan 2020 11:14:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=k+VUD8nMOJexiRrso/z9z6w71tA5W71aT5QRjQZsCus=; b=F7c7PtgxjFSvZI32Vsh1jpBsn5XYs83l9aK2dKEOKbYH9bLiq2ILisDu0QsTESCv/N r0vBzNv9daYRh7NMv5GFZbMazEFCQFuKUbYL3ACZpa9ZX2BOngJ7J0mTyOV7YlnFS3k8 MjIE3qivFW/mASgt+cddWugPDswdg064tqJf3NN1krKv+An5NVqdxgh+/aw9nuAy+GJd s1IgtceisDTaq1JfPANQQsFSdjZFJqsJvJxaiaZZHSm+TX4vRuyEqP6C9wpEMYFN5lcM 4g+hZYv3rOCFdfnKtx7oPAZLPlMR87xS+aH+Opplb1dPxFNo7Wuha61hMEay+7hmQaAP 1A5A== Return-Path: Received: from ?IPv6:2620:10d:c0a8:1102:200f:5964:bddb:30be? ([2620:10d:c091:480::bd27]) by smtp.googlemail.com with ESMTPSA id n190sm7206467qke.90.2020.01.14.11.14.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Jan 2020 11:14:23 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: [PR90916] ICE in retrieve specialization Message-ID: <2c6315cb-f1d3-b0fe-6837-fb9fe571daeb@acm.org> Date: Tue, 14 Jan 2020 20:29:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------8270D916D96ACB71F7F864EB" X-SW-Source: 2020-01/txt/msg00812.txt.bz2 This is a multi-part message in MIME format. --------------8270D916D96ACB71F7F864EB Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 744 This fixes an ICE caused by a cleanup of get_class_binding. Previously its type_or_fn parm defaulted to -1, which had some funky behaviour I convinced myself was irrelevant to C++ source. Here we're peeking behind the curtain of a class under construction, and previously the -1 behaviour caused us never to see a type here -- we could only get back function decls, because we only looked in the method_vector (and that's only created during construction if there are functions). so, look at DECL_TEMPLATE_INFO or CLASSTYPE_TEMPLATE_INFO depending on what we got back. Incidentally, this means we will now optimize member class instantiations in this case, whereas before we didn't. Committing to trunk. nathan -- Nathan Sidwell --------------8270D916D96ACB71F7F864EB Content-Type: text/x-patch; charset=UTF-8; name="90916.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="90916.diff" Content-length: 1784 diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 004ce0fdcdf..3cc7c48b490 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2020-01-14 Nathan Sidwell + + PR c++/90916 + * pt.c (retrieve_specialization): Get the TI from the decl or the + classtype as appropriate. + 2020-01-14 David Malcolm * cp-gimplify.c (source_location_table_entry_hash::empty_zero_p): diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index fa82ecad233..4fdc74f9ca8 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -1252,11 +1252,16 @@ retrieve_specialization (tree tmpl, tree args, hashval_t hash) for (ovl_iterator iter (fns); iter; ++iter) { tree fn = *iter; - if (DECL_TEMPLATE_INFO (fn) && DECL_TI_TEMPLATE (fn) == tmpl - /* using-declarations can add base methods to the method vec, - and we don't want those here. */ - && DECL_CONTEXT (fn) == class_specialization) - return fn; + if (tree ti = (TREE_CODE (fn) == TYPE_DECL && !TYPE_DECL_ALIAS_P (fn) + ? TYPE_TEMPLATE_INFO (TREE_TYPE (fn)) + : DECL_TEMPLATE_INFO (fn))) + if (TI_TEMPLATE (ti) == tmpl + /* using-declarations can bring in a different + instantiation of tmpl as a member of a different + instantiation of tmpl's class. We don't want those + here. */ + && DECL_CONTEXT (fn) == class_specialization) + return fn; } return NULL_TREE; } diff --git a/gcc/testsuite/g++.dg/template/pr90916.C b/gcc/testsuite/g++.dg/template/pr90916.C new file mode 100644 index 00000000000..bdb7e7b58ef --- /dev/null +++ b/gcc/testsuite/g++.dg/template/pr90916.C @@ -0,0 +1,8 @@ +// PR c++/90916 ICE in retrieve_specialization + +template struct S +{ + struct A; + struct f A (); +}; +template class S ; --------------8270D916D96ACB71F7F864EB--