From patchwork Wed Feb 7 21:16:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 870637 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-472793-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="cYyBjacO"; 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 3zcDf36y4Zz9t3C for ; Thu, 8 Feb 2018 08:16:26 +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 :subject:references:to:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=gqSGy7mjQx/l0By2A iGnMzBu+hQlCNo8NRyA505lpoGUWxOVmtdmgv31xICU5i37chBDD7ngKfNglL7+a ySLG4rrE6WLUsqw4/TDW62a3WVElcv++gjlpecU3hxm95yioXqYUt1o7ZXWoXngz aLq1HsAHioi1dyJ+6QQARtOpxI= 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 :subject:references:to:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=Vt+aV5O9sZR09tQBdbX+LbG gUPc=; b=cYyBjacOP1QYUfhwXuimYqbBIaLSdCfH/F+YDFH3gY2TCTdj3THzao5 c355qoT4SAGYvTCl/4dK1TmddQLyeQZYFWTvca6H1idTdxPUdWiFg6VaPhfwbBQI 5gEHmw1osf/xWwIF/s92sOWthvd2p2MjykrL8PrAnlK+HHyVskm8= Received: (qmail 79527 invoked by alias); 7 Feb 2018 21:16:18 -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 79248 invoked by uid 89); 7 Feb 2018 21:16:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: aserp2120.oracle.com Received: from aserp2120.oracle.com (HELO aserp2120.oracle.com) (141.146.126.78) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Feb 2018 21:16:10 +0000 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w17LETiM087139 for ; Wed, 7 Feb 2018 21:16:08 GMT Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2120.oracle.com with ESMTP id 2g096w00gt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 07 Feb 2018 21:16:08 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w17LG74r006933 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 7 Feb 2018 21:16:07 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w17LG7oh014849 for ; Wed, 7 Feb 2018 21:16:07 GMT Received: from [192.168.1.4] (/79.52.198.133) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 07 Feb 2018 13:16:07 -0800 Subject: [C++ Patch/RFC] PR 83204 ("[6/7/8 Regression] c++ -std=c++14 ICE in maybe_undo_parenthesized_ref, at cp/semantics.c:1694") References: To: "gcc-patches@gcc.gnu.org" From: Paolo Carlini X-Forwarded-Message-Id: Message-ID: <6789fba4-fd92-587f-bed2-09ae4cb0398c@oracle.com> Date: Wed, 7 Feb 2018 22:16:05 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8798 signatures=668663 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1802070267 X-IsSubscribed: yes Hi, this is essentially an RFC, I'm still fully analyzing the issue, but since I already have something prima facie reasonable and passing the testsuite I decided to send immediately out what I have, looking for further feedback / help. As fully analyzed by Jakub in the audit trail, for the testcase - it's important detail being the parentheses around x in the for(int y = 0, yend = (x); y < yend; ++y) part of the lambda body - we ICE in maybe_undo_parenthesized_ref when we hit the assert:       gcc_assert (TREE_CODE (t) == ADDR_EXPR           || TREE_CODE (t) == STATIC_CAST_EXPR); because in tsubst_copy_and_build for INDIRECT_REF we do: -    if (TREE_CODE (r) == INDIRECT_REF) -      REF_PARENTHESIZED_P (r) = REF_PARENTHESIZED_P (t); +    if (REF_PARENTHESIZED_P (t)) +      r = force_paren_expr (r); irrespective of the details of r beyond it being an INDIRECT_REF. Today something I immediately noticed, beyond all the ideas provided by Jakub in the trail, is that in all the other places in pt.c, besides maybe one case in tsubst_qualified_id, where we adjust REF_PARENTHESIZED_P either we use indeed force_paren_expr which is guaranteed to produce something consistent with maybe_undo_parenthesized_ref, or we simply do things like:         if (TREE_CODE (r) == COMPONENT_REF)           REF_PARENTHESIZED_P (r) = REF_PARENTHESIZED_P (t); where in fact force_paren_expr would simply handle a COMPONENT_REF in the same way. Thus the idea of the draft patch. Jason, if you see something deeper going on which you would rather prefer to handle yourself, please let me know and I'll adjust the bug owner appropriately. Thanks! Paolo. //////////////////// Index: cp/pt.c =================================================================== --- cp/pt.c (revision 257458) +++ cp/pt.c (working copy) @@ -17224,8 +17224,8 @@ tsubst_copy_and_build (tree t, r = build_x_indirect_ref (input_location, r, RO_UNARY_STAR, complain|decltype_flag); - if (TREE_CODE (r) == INDIRECT_REF) - REF_PARENTHESIZED_P (r) = REF_PARENTHESIZED_P (t); + if (REF_PARENTHESIZED_P (t)) + r = force_paren_expr (r); RETURN (r); } Index: testsuite/g++.dg/cpp0x/lambda/lambda-ice25.C =================================================================== --- testsuite/g++.dg/cpp0x/lambda/lambda-ice25.C (nonexistent) +++ testsuite/g++.dg/cpp0x/lambda/lambda-ice25.C (working copy) @@ -0,0 +1,27 @@ +// PR c++/83204 +// { dg-do compile { target c++11 } } + +int rand(); + +template +struct s +{ + int count() { return rand(); } +}; + +template +void f(s a) +{ + int const x = a.count(); + int r = 0; + auto l = [&](int& r) + { + for(int y = 0, yend = (x); y < yend; ++y) + { + r += y; + } + }; + l(r); +} + +template void f(s);