From patchwork Mon Apr 1 09:36:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1072548 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-498696-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="GAF4MO4Z"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="rKkiSLOy"; dkim-atps=neutral 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 44XnL727Pgz9sQt for ; Mon, 1 Apr 2019 20:37:01 +1100 (AEDT) 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=wHPfHMLtUq0GC/83JZJyBbE3j3QMzsXH1yh0t8X3fr0+UOakwN HsQ5Kd5JpigP6txFR6aSCnYSL4RMAxDrqF7JZcvz6GvXwqA+qZ2BUgL5vYROduga 1jZtRKuUJx9MMLK6RVQ62dz2Ooq8ibRYKgPLkPRxMVLWYm45+1hz/Ac7s= 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=PlBNUlwb1FYWoVHVlezTYq39wUo=; b=GAF4MO4ZIqVrfLjYzc6b t2JOAIdFcrRKsdzELUz3gBRpw4VfjBYtLvS9bt7jdP9mwg+YKibfVpTq8MZm6QvG 2XGUK2Mgkuz/BXNR0xhVMOCQCJIHxrlg2zQo291/Z9nmWNszNpYWUZnv4AuZK1Vs NdLLdN2bVpccjMupgvO3jG0= Received: (qmail 23331 invoked by alias); 1 Apr 2019 09:36:53 -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 22982 invoked by uid 89); 1 Apr 2019 09:36:53 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-8.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=62207, interestingly, ctx X-HELO: aserp2130.oracle.com Received: from aserp2130.oracle.com (HELO aserp2130.oracle.com) (141.146.126.79) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 01 Apr 2019 09:36:51 +0000 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x319aEkp118748; Mon, 1 Apr 2019 09:36:49 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=to : cc : from : subject : message-id : date : mime-version : content-type; s=corp-2018-07-02; bh=s0k1GzDZ6nSjlmMKJkXyWzUk1zZYMwFYZ+g/RMmfqAA=; b=rKkiSLOy95xDHAQB4HgFO+g040O8LKH751faED0j+vs/KU1R4h/YrY8AWg2QUJinYkfQ 1QfWcaLzL1dFy9EU5l9HODMJ3YVxL+HyjSx8yygScoWUK9tZC9eH0fDQaidxEqLcLTJV 2GaDSnVRc/lTbBhy0Rlp7aS7lpBx0rWyPHW+Djc1Ucsmtxd+Z1aLMjHyXTszmobUHo71 dQpLTTPcMqqOk/UGmcYixzG1u1owSXKzl9SOLr0Otfm7YDGeW/wcZbTYIq33IkqFiY/r 3y6mHR76/wjlHnaEojV7oLWBuyUo4wr3YiSASpA7SOcC6+GwDQgzhpsqlFiidbe8pkAQ 1A== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2rhwycx07j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 01 Apr 2019 09:36:49 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x319ahsH019221 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 1 Apr 2019 09:36:43 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x319agW7014956; Mon, 1 Apr 2019 09:36:42 GMT Received: from [192.168.1.4] (/79.49.225.17) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 01 Apr 2019 02:36:41 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] PR 62207 ("[7/8/9 Regression] ICE: tree check: expected tree that contains 'decl minimal' structure, have 'overload' in tsubst_copy, at cp/pt.c") Message-ID: <5ef65014-32c6-97e4-92d9-60bf7dc466b1@oracle.com> Date: Mon, 1 Apr 2019 11:36:38 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 X-IsSubscribed: yes Hi, A rather long standing issue. The error-recovery problem is that, in various circumstances, we flag as erroneous a local variable declaration and then, when we need to come back to it later on, lookup_name doesn't find it, keeps looking and may find instead a completely unrelated non-variable declaration with the same name. In principle, we could probably set up things in such a way that during error-recovery the erroneous entity is found anyway, marked as erroneous of course, but I don't think we want to attempt that now... Thus, I'm proposing to just check for VAR_P in the relevant case of tsubst_copy and bail-out. Setting instead r = NULL_TREE and trying to continue works rather well but leads to duplicate diagnostics in some cases (eg, for template/crash131.C). By the way, something else I actually tried is returning immediately from tsubst_expr when the tsubst call in case DECL_EXPR returns error_mark_node and then bail out immediately from the for loop over the STATEMENT_LIST. That also passes the testsuite, but, if you want, you can certainly notice that the loop over the statements ends early, for example we would not provide any diagnostics for an additional Y y2; in template/crash131.C. Which interestingly is true for current clang too ;) Tested x86_64-linux. Thanks, Paolo. ///////////////////// /cp 2019-04-01 Paolo Carlini PR c++/62207 * pt.c (tsubst_copy): Deal with lookup_name not returing a variable. /testsuite 2019-04-01 Paolo Carlini PR c++/62207 * g++.dg/template/crash130.C: New. * g++.dg/template/crash131.C: Likewise. Index: cp/pt.c =================================================================== --- cp/pt.c (revision 270012) +++ cp/pt.c (working copy) @@ -15579,12 +15579,23 @@ tsubst_copy (tree t, tree args, tsubst_flags_t com { /* First try name lookup to find the instantiation. */ r = lookup_name (DECL_NAME (t)); - if (r && !is_capture_proxy (r)) + if (r) { - /* Make sure that the one we found is the one we want. */ - tree ctx = enclosing_instantiation_of (DECL_CONTEXT (t)); - if (ctx != DECL_CONTEXT (r)) - r = NULL_TREE; + if (!VAR_P (r)) + { + /* During error-recovery we may find a non-variable, + even an OVERLOAD: just bail out and avoid ICEs and + duplicate diagnostics (c++/62207). */ + gcc_assert (seen_error ()); + return error_mark_node; + } + if (!is_capture_proxy (r)) + { + /* Make sure the one we found is the one we want. */ + tree ctx = enclosing_instantiation_of (DECL_CONTEXT (t)); + if (ctx != DECL_CONTEXT (r)) + r = NULL_TREE; + } } if (r) @@ -15620,7 +15631,7 @@ tsubst_copy (tree t, tree args, tsubst_flags_t com } gcc_assert (cp_unevaluated_operand || TREE_STATIC (r) || decl_constant_var_p (r) - || errorcount || sorrycount); + || seen_error ()); if (!processing_template_decl && !TREE_STATIC (r)) r = process_outer_var_ref (r, complain); Index: testsuite/g++.dg/template/crash130.C =================================================================== --- testsuite/g++.dg/template/crash130.C (nonexistent) +++ testsuite/g++.dg/template/crash130.C (working copy) @@ -0,0 +1,15 @@ +// PR c++/62207 + +template void foo(T) +{ + X; // { dg-error "not declared" } + X; +} + +void X(); +void X(int); + +void bar() +{ + foo(0); +} Index: testsuite/g++.dg/template/crash131.C =================================================================== --- testsuite/g++.dg/template/crash131.C (nonexistent) +++ testsuite/g++.dg/template/crash131.C (working copy) @@ -0,0 +1,16 @@ +// PR c++/62207 + +template +class X { +public: + template class Y {}; + template void y() {} + X(F f) + { + Y y; // { dg-error "not a constant" } + + y.value(); + } +}; + +int main() { X x(1); }