From patchwork Tue Jan 16 20:32:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 861876 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-471417-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="ZGfMZBEa"; 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 3zLhk66Zm2z9s7F for ; Wed, 17 Jan 2018 07:33: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=FO+ZQbH4KhB5xi7Hx6IZH2NwOg0bwHaVUhMCTHpVaLeO/TkJCw +pvzUoLLa3FEPgjgxu2D/uUkskPPBLcD+qfhYojHOtmhAs5433Lb2qNF5vfZz7Sl V2qEIzUU/rFmH6h1DcK4aHSnUfbl4M/2O+gx9sTJKPUMVth7hhSRxD8oY= 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=PYyWpH83ghi3Z2g8qQvIFzqSYeE=; b=ZGfMZBEaH5ydorwH7P6f hF5zGIG1GeYWba8QU5YuRhVZh3KgI52hN+vZZZfr2HKvRZEckS4XjvGDfNTfm3WF 9yINQaQBa2LTSf/U4ZG7r4dAWJ4aD9swK2amrZsQh6e3UqH5CL5dZv0K6QNm+rZu 6vfnggIMvMHQyFB57JNHMMI= Received: (qmail 9188 invoked by alias); 16 Jan 2018 20:32:29 -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 9002 invoked by uid 89); 16 Jan 2018 20:32:27 -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, 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; Tue, 16 Jan 2018 20:32:25 +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 w0GKVgtd151202; Tue, 16 Jan 2018 20:32:19 GMT Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2fhqw8877t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Jan 2018 20:32:19 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w0GKWIUa008568 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 16 Jan 2018 20:32:18 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w0GKWHva011333; Tue, 16 Jan 2018 20:32:17 GMT Received: from [192.168.1.4] (/95.250.222.138) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 16 Jan 2018 12:32:17 -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") [Take 2] Message-ID: <9dc00709-5f5e-6bf3-1ece-999edade8a84@oracle.com> Date: Tue, 16 Jan 2018 21:32:14 +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=8776 signatures=668653 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-1801160282 X-IsSubscribed: yes Hi again, thus I figured out what was badly wrong in my first try: I misread ensure_literal_type_for_constexpr_object and missed that it can return NULL_TREE without emitting an hard error. Thus my first try even caused miscompilations :( Anyway, when DECL_DECLARED_CONSTEXPR_P is true we are safe and indeed we want to clear it as matter of error recovery. Then, in this safe case the only change in the below is returning early, thus avoiding any internal inconsistencies later and also the redundant / misleading diagnostic which I already mentioned. Testing on x86_64-linux is still in progress - in libstdc++ - but I separately checked that all the regressions are gone. Thanks! Paolo. ///////////////////// /cp 2018-01-16 Paolo Carlini PR c++/81054 * decl.c (cp_finish_decl): Early return when ensure_literal_type_for_constexpr_object returns NULL_TREE and DECL_DECLARED_CONSTEXPR_P is true. /testsuite 2018-01-16 Paolo Carlini PR c++/81054 * g++.dg/cpp0x/constexpr-ice19.C: New. Index: cp/decl.c =================================================================== --- cp/decl.c (revision 256753) +++ cp/decl.c (working copy) @@ -6810,8 +6810,12 @@ cp_finish_decl (tree decl, tree init, bool init_co cp_apply_type_quals_to_decl (cp_type_quals (type), decl); } - if (!ensure_literal_type_for_constexpr_object (decl)) - DECL_DECLARED_CONSTEXPR_P (decl) = 0; + if (!ensure_literal_type_for_constexpr_object (decl) + && DECL_DECLARED_CONSTEXPR_P (decl)) + { + DECL_DECLARED_CONSTEXPR_P (decl) = 0; + return; + } if (VAR_P (decl) && DECL_CLASS_SCOPE_P (decl) 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" } +};