From patchwork Tue Aug 29 09:33:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 807010 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-461070-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="tAjUZXx5"; 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 3xhNkn0Q3bz9t2x for ; Tue, 29 Aug 2017 19:34:24 +1000 (AEST) 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=uKr0mHIsQeSVD1HRnYwEwu0dwpz+KXxKpxI2FdNVVrHIt5jAZE /jhrwLuGVTp8hzHOXN+2thfdaaywevNIB6rMFvp5WcBsH2SPBwzwctQ/56CfdoJ/ KdkKm5dcgKWxmTccFt70BLma2jnWAxW+ZNMpKRbfw9Rti0IUDyisCt/QQ= 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=QhuBCUjyfTVQ2llzs8Y466gTJy0=; b=tAjUZXx5Ylyq55eY3zVS +UEVOGazkYhmSniozOghjJAYn/oPM8rl96OSMVBWNUDjn2sLhLSA8UMR4OSptu1B OO8bP+lXge3Mfbyjb8ArtVX6OFh0AzmSvpnCgHRuvbl2zIsDoX/jkPWQuyEqEceP sE29MiWmdscOAmb3SITt1V4= Received: (qmail 130877 invoked by alias); 29 Aug 2017 09:34:14 -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 130857 invoked by uid 89); 29 Aug 2017 09:34:12 -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, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=(unknown), H*r:ip*192.168.1.4, Hx-spam-relays-external:192.168.1.4, H*RU:192.168.1.4 X-HELO: aserp1040.oracle.com Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 29 Aug 2017 09:34:02 +0000 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v7T9XxMr002954 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Aug 2017 09:34:00 GMT 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 v7T9XxFW021097 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Aug 2017 09:33:59 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v7T9Xw9P012580; Tue, 29 Aug 2017 09:33:58 GMT Received: from [192.168.1.4] (/79.30.90.105) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 29 Aug 2017 02:33:58 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] PR 70621 ("[6/7/8 Regression] ICE on invalid code at -O1 and above on x86_64-linux-gnu in record_reference, at cgraphbuild.c:64") Message-ID: <7c782ea8-b832-3e1b-ce83-cca08866f4c8@oracle.com> Date: Tue, 29 Aug 2017 11:33:55 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, in this error recovery regression, we ICE only when optimizing, while building the cgraph. Avoiding the reported problem seems easy, just check the return value of duplicate_decls in start_decl and immediately return back error_mark_node. However, while working on the issue, I noticed something slightly more interesting, IMO: we have, after the relevant duplicate_decls call: - if (decl_spec_seq_has_spec_p (declspecs, ds_constexpr) - && !DECL_DECLARED_CONSTEXPR_P (field)) - error ("%qD declared % outside its class", field); which I propose to remove. In fact - something I didn't really know - for well formed user code, duplicate_decls, near the end, does some memcpys which mean that its second argument (would be 'field' in the start_decl section we are looking at) is adjusted to have a DECL_DECLARED_CONSTEXPR_P consistent with its first argument. That's of course because we want to accept snippets like: struct A { static const int x; }; constexpr int A::x = 0; In turn that means the error above is issued only when something went wrong in duplicate_decls in the first place. Thus the above error seems at least verbose. However, here in start_decl we are only handling VAR_P (decl), thus I don't think the message above even makes sense and could be misleading, given snippets like the above. Therefore, I propose to remove the diagnostic entirely, which overall also simplifies a patch dealing with c++/70621. The below passes testing as-is on x86_64-linux. Thanks, Paolo. //////////////////////// /cp 2017-29-08 Paolo Carlini PR c++/70621 * decl.c (start_decl): Early return error_mark_node if duplicate_decls returns it; avoid misleading error message. /testsuite 2017-29-08 Paolo Carlini PR c++/70621 * g++.dg/torture/pr70621.C: New. Index: cp/decl.c =================================================================== --- cp/decl.c (revision 251375) +++ cp/decl.c (working copy) @@ -5023,11 +5023,12 @@ start_decl (const cp_declarator *declarator, about this situation, and so we check here. */ if (initialized && DECL_INITIALIZED_IN_CLASS_P (field)) error ("duplicate initialization of %qD", decl); - if (duplicate_decls (decl, field, /*newdecl_is_friend=*/false)) + field = duplicate_decls (decl, field, + /*newdecl_is_friend=*/false); + if (field == error_mark_node) + return error_mark_node; + else if (field) decl = field; - if (decl_spec_seq_has_spec_p (declspecs, ds_constexpr) - && !DECL_DECLARED_CONSTEXPR_P (field)) - error ("%qD declared % outside its class", field); } } else Index: testsuite/g++.dg/torture/pr70621.C =================================================================== --- testsuite/g++.dg/torture/pr70621.C (revision 0) +++ testsuite/g++.dg/torture/pr70621.C (working copy) @@ -0,0 +1,13 @@ +float foo(); + +struct A +{ + static float x; // { dg-message "previous declaration" } +}; + +double A::x = foo(); // { dg-error "conflicting declaration" } + +void bar() +{ + A::x = 0; +}