From patchwork Mon Nov 19 19:03:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1000052 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-490448-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="ydVU6NDi"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="4mNE2Iq7"; 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 42zJCL18YKz9s8r for ; Tue, 20 Nov 2018 06:03:39 +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=F1qmIYdN1arSU9m4UUDNuWJJHfS2sE/5F4QAFI5RCicXm0mToM TArkNG0UTRGnhvTNrNxSLD8vmzopYPUyeafBIW6QBq4rGFmHVIKMdlyCAwTb8wTD JSgbCBddl8xR47rhhwr5GJz/3Mf+XqPrc65mdb5jERYrRTU/ga9yZuIVk= 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=/dgXRMgjZtkFR96FAWEFynUMa8U=; b=ydVU6NDign5+RcypqdaH JM7JbkBGDjP5rYbFZvcf0RlV4ikuxc/kax8hVWmDNK6sUm4u0AVK/0pjWAF0OwWv WLBpfyPs+YWtgZctDPJBE3ahtBUGuV8NiDxYUFsfGONLKeV7ToxWkJ6f+wfCL8Hv nJesdrtp+bO0Pxe+wM14HTs= Received: (qmail 23418 invoked by alias); 19 Nov 2018 19:03:32 -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 23401 invoked by uid 89); 19 Nov 2018 19:03:32 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=declarator, paolo, stumbled, Paolo 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; Mon, 19 Nov 2018 19:03:30 +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 wAJIxDJv064425; Mon, 19 Nov 2018 19:03:28 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=f4cJNkrHqVXHWfHRurl9vYBgn+nFgwyo/M+r2KLPz2k=; b=4mNE2Iq7przHzEmZO4nd4YJhGkoD/9Zfpxfk0WJ7w1RC1/gWMpUx5paF5q1dkhSmcNcn GaCHKuTAy99vP/IEghnIlcVbK5+cUcNrNd+etOqmqVt0LFUid7BSxsuCpRTCj3owmP8R N4TdhnrqfL1sw/X0mBThkKYA5pbWHnRDJbmIZIlkvsX7dwz8juev1qPJXvz5X9LbJafv sUmzrTFqBs+CbbZmVOZBjEhm8uFevJW23Zc6Yj8ylA6sRQP9ZhlhE5ZSJ9FgiNTto+Kt meAArBcZ0rQpWWMOB5eHsJmxpE47BqMn2f8UamFe2Mnbs8Lda24Xlp1jR6dm4jp7HgLN ag== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2120.oracle.com with ESMTP id 2ntaxpyvt8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Nov 2018 19:03:28 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id wAJJ3SQ4028172 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Nov 2018 19:03:28 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id wAJJ3RXm021852; Mon, 19 Nov 2018 19:03:27 GMT Received: from [192.168.1.4] (/87.21.103.159) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 19 Nov 2018 11:03:26 -0800 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] PR 84636 ("internal compiler error: Segmentation fault (identifier_p()/grokdeclarator())") Message-ID: <7e0b3ae8-3c74-f2a3-29f3-351b1d105a4b@oracle.com> Date: Mon, 19 Nov 2018 20:03:24 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, while working on some additional location fixes to grokbitfield - preparing testcases - I stumbled into this ICE on invalid, where in grokdeclarator we try to use identifier_p on a null unqualified_id. In practice, clang and edg behave in different ways and since I couldn't decide which one I liked best I prepared two different patches which, respectively, implement similar behaviors: the former avoids the grokdeclarator ICE and delegates to the checks in grokbitfield for the diagnostics; the latter issues a specific error about the missing identifier after a function type (note, in any case we want to do that when staticp == 2 too, otherwise we crash later for a static version of the declaration). Tested both onx86_64-linux, as usual. Thanks, Paolo. //////////////// Index: cp/decl.c =================================================================== --- cp/decl.c (revision 266268) +++ cp/decl.c (working copy) @@ -12164,15 +12164,24 @@ grokdeclarator (const cp_declarator *declarator, type = build_pointer_type (type); } - if (ctype && TREE_CODE (type) == FUNCTION_TYPE && staticp < 2 - && !(identifier_p (unqualified_id) - && IDENTIFIER_NEWDEL_OP_P (unqualified_id))) + if (ctype && TREE_CODE (type) == FUNCTION_TYPE) { - cp_cv_quals real_quals = memfn_quals; - if (cxx_dialect < cxx14 && constexpr_p - && sfk != sfk_constructor && sfk != sfk_destructor) - real_quals |= TYPE_QUAL_CONST; - type = build_memfn_type (type, ctype, real_quals, rqual); + if (!unqualified_id) + { + error_at (declspecs->locations[ds_type_spec], + "declarator requires an identifier"); + type = error_mark_node; + } + else if (staticp < 2 + && !(identifier_p (unqualified_id) + && IDENTIFIER_NEWDEL_OP_P (unqualified_id))) + { + cp_cv_quals real_quals = memfn_quals; + if (cxx_dialect < cxx14 && constexpr_p + && sfk != sfk_constructor && sfk != sfk_destructor) + real_quals |= TYPE_QUAL_CONST; + type = build_memfn_type (type, ctype, real_quals, rqual); + } } { Index: testsuite/g++.dg/parse/bitfield6.C =================================================================== --- testsuite/g++.dg/parse/bitfield6.C (nonexistent) +++ testsuite/g++.dg/parse/bitfield6.C (working copy) @@ -0,0 +1,6 @@ +// PR c++/84636 + +typedef void a(); +struct A { + a: 1; // { dg-error "3:declarator requires an identifier" } +}; Index: cp/decl.c =================================================================== --- cp/decl.c (revision 266268) +++ cp/decl.c (working copy) @@ -12165,7 +12165,8 @@ grokdeclarator (const cp_declarator *declarator, } if (ctype && TREE_CODE (type) == FUNCTION_TYPE && staticp < 2 - && !(identifier_p (unqualified_id) + && !(unqualified_id + && identifier_p (unqualified_id) && IDENTIFIER_NEWDEL_OP_P (unqualified_id))) { cp_cv_quals real_quals = memfn_quals; @@ -12245,8 +12246,9 @@ grokdeclarator (const cp_declarator *declarator, error ("invalid use of %<::%>"); return error_mark_node; } - else if (TREE_CODE (type) == FUNCTION_TYPE - || TREE_CODE (type) == METHOD_TYPE) + else if ((TREE_CODE (type) == FUNCTION_TYPE + || TREE_CODE (type) == METHOD_TYPE) + && !bitfield) { int publicp = 0; tree function_context; Index: testsuite/g++.dg/parse/bitfield3.C =================================================================== --- testsuite/g++.dg/parse/bitfield3.C (revision 266263) +++ testsuite/g++.dg/parse/bitfield3.C (working copy) @@ -5,5 +5,5 @@ typedef void (func_type)(); struct A { - friend func_type f : 2; /* { dg-error "with non-integral type" } */ + friend func_type f : 2; /* { dg-error "20:.f. is neither function nor member function" } */ }; Index: testsuite/g++.dg/parse/bitfield6.C =================================================================== --- testsuite/g++.dg/parse/bitfield6.C (nonexistent) +++ testsuite/g++.dg/parse/bitfield6.C (working copy) @@ -0,0 +1,6 @@ +// PR c++/84636 + +typedef void a(); +struct A { +a: 1; // { dg-error "bit-field .\\. with non-integral type" } +};