From patchwork Tue Jan 16 10:37:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 861400 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-471353-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="BT2reCGJ"; 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 3zLRWG450cz9s7M for ; Tue, 16 Jan 2018 21:37:46 +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=NCbaMmq7J5G61bfNzo41vkm7YEBuKccwCHF26E6lhOokkh41fb VH5U842/V4fs2m0QIbzrDf7LF/WlA+G5tBnU7ZeOfbdbnqZqYsakvEIexKnLoQr4 2F/tIr2RJki4fnDC3syRu23mRCfD/sKldvFRoCLIn1IJ1j7gJEDIb0X+w= 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=8g3+yEyTqTA0qelhBV2Z0NTFEhg=; b=BT2reCGJ3pQRaYc7XJX2 S5N1LotQos++YAznto1tGQ/eMg3QyMgWGXnrKW8qSUW9zslVyw/rm8RS/Qz4vbc0 VIXUJaFHxrWhRzVYR2DyWja/Afa57gRMJPd0mJEr59tbkTDVzHp6mCmCtukRvSeY y/8RjOvkbKETD3VZMSzYJjw= Received: (qmail 129312 invoked by alias); 16 Jan 2018 10:37:35 -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 129215 invoked by uid 89); 16 Jan 2018 10:37:34 -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=Early, H*r:ip*192.168.1.4, Hx-spam-relays-external:192.168.1.4, H*RU:192.168.1.4 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; Tue, 16 Jan 2018 10:37:24 +0000 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w0GAQwRn097121; Tue, 16 Jan 2018 10:37:21 GMT Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2130.oracle.com with ESMTP id 2fhf8m86jh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Jan 2018 10:37:21 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w0GAbLeD019312 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 16 Jan 2018 10:37:21 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w0GAbKP3026182; Tue, 16 Jan 2018 10:37:20 GMT Received: from [192.168.1.4] (/95.250.222.138) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 16 Jan 2018 02:37:20 -0800 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill , Nathan Sidwell From: Paolo Carlini Subject: [C++ Patch] PR 81054 ("[7/8 Regression] ICE with volatile variable in constexpr function") Message-ID: <7c9190ae-8852-2bfa-99b4-f3dcee89198d@oracle.com> Date: Tue, 16 Jan 2018 11:37:17 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8775 signatures=668652 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-1801160153 X-IsSubscribed: yes Hi, in this error recovery regression we ICE when we end-up in an inconsistent state after meaningful diagnostic emitted by ensure_literal_type_for_constexpr_object and then some redundant / slightly misleading one emitted by check_static_variable_definition. I think we can just return early from cp_finish_decl and solve the primary and the secondary issue. I also checked that clang too doesn't emit an error for line #28 of constexpr-diag3.C, after the hard error for co1 itself at line #27. Tested x86_64-linux. Thanks, Paolo. ////////////////////// /cp 2018-01-61 Paolo Carlini PR c++/81054 * decl.c (cp_finish_decl): Early return when the ensure_literal_type_for_constexpr_object fails. /testsuite 2018-01-61 Paolo Carlini PR c++/81054 * g++.dg/cpp0x/constexpr-ice19.C: New. * g++.dg/cpp0x/constexpr-diag3.C: Adjust. Index: cp/decl.c =================================================================== --- cp/decl.c (revision 256728) +++ cp/decl.c (working copy) @@ -6811,7 +6811,11 @@ cp_finish_decl (tree decl, tree init, bool init_co } if (!ensure_literal_type_for_constexpr_object (decl)) - DECL_DECLARED_CONSTEXPR_P (decl) = 0; + { + DECL_DECLARED_CONSTEXPR_P (decl) = 0; + TREE_TYPE (decl) = error_mark_node; + return; + } if (VAR_P (decl) && DECL_CLASS_SCOPE_P (decl) Index: testsuite/g++.dg/cpp0x/constexpr-diag3.C =================================================================== --- testsuite/g++.dg/cpp0x/constexpr-diag3.C (revision 256728) +++ testsuite/g++.dg/cpp0x/constexpr-diag3.C (working copy) @@ -25,7 +25,7 @@ struct complex // { dg-message "no .constexpr. }; constexpr complex co1(0, 1); // { dg-error "not literal" } -constexpr double dd2 = co1.real(); // { dg-error "|in .constexpr. expansion of " } +constexpr double dd2 = co1.real(); // -------------------- Index: testsuite/g++.dg/cpp0x/constexpr-ice19.C =================================================================== --- testsuite/g++.dg/cpp0x/constexpr-ice19.C (nonexistent) +++ testsuite/g++.dg/cpp0x/constexpr-ice19.C (working copy) @@ -0,0 +1,13 @@ +// PR c++/81054 +// { dg-do compile { target c++11 } } + +struct A +{ + volatile int i; + constexpr A() : i() {} +}; + +struct B +{ + static constexpr A a {}; // { dg-error "not literal" } +};