From patchwork Wed Mar 16 10:29:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1606102 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=sR4R5nZW; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KJRP060jzz9sCD for ; Wed, 16 Mar 2022 21:30:11 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 85B95385EC59 for ; Wed, 16 Mar 2022 10:30:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 85B95385EC59 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1647426608; bh=aadp3dhtsV+abUti9NkfTJxPlcWucyng1tn8OkglPKA=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=sR4R5nZW9gN4OM2IpaUbYrfcYOZKG1VtQPAAQnpY7WP/LhjeO/Od0GLzXfkVWqz3M iiYKTQEgsDYwEMdXToxt5XhWMJoKK4frmkJUmmrHTRC2i0X4QT/7mlibrHWKXMFndQ ubI61t+ZFCrlfOHnX12xy7q6hX8L91Klyj3qYjj0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 435083857806 for ; Wed, 16 Mar 2022 10:29:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 435083857806 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-256-Xeq1i28UP9GkdWIUTqYBWg-1; Wed, 16 Mar 2022 06:29:25 -0400 X-MC-Unique: Xeq1i28UP9GkdWIUTqYBWg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6F4001801387 for ; Wed, 16 Mar 2022 10:29:25 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.81]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0F5C0112C088; Wed, 16 Mar 2022 10:29:24 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 22GATLj53112399 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 16 Mar 2022 11:29:22 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 22GATLs73111765; Wed, 16 Mar 2022 11:29:21 +0100 Date: Wed, 16 Mar 2022 11:29:20 +0100 To: Jason Merrill , gcc-patches Paul A Clarke via Subject: [PATCH] c-family: Fix ICE in pp_cxx_unqualified_id, at cp/cxx-pretty-print.c:128 [PR101515] Message-ID: References: <946D3718-32CD-45B6-8EF5-C41DDC3CA06E@oracle.com> <87823a36-93f3-5541-dc76-5a8c32e51c03@redhat.com> <319ad931-a975-e29c-7b8a-51534d657e01@redhat.com> <9B1729F5-964A-4A12-93B3-148BFE4D96F5@oracle.com> <01B0A297-CC89-4666-9684-BE04BE17E66E@oracle.com> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" On Tue, Mar 15, 2022 at 01:32:46PM +0100, Jakub Jelinek via Gcc-patches wrote: > Another one is whether we shouldn't punt for FIELD_DECLs that don't have > nicely printable name of its containing scope, something like: > if (tree scope = get_containing_scope (field)) > if (TYPE_P (scope) && TYPE_NAME (scope) == NULL_TREE) > break; > return cop; > or so. This seems to work fine, ok if it passes bootstrap/regtest? No need to do it for C because it doesn't print the contexts (has no syntax for that even). 2022-03-16 Jakub Jelinek PR c++/101515 * c-pretty-print.cc (c_fold_indirect_ref_for_warn): For C++ don't return COMPONENT_REFs with FIELD_DECLs whose containing scope can't be printed. * g++.dg/warn/pr101515.C: New test. Jakub --- gcc/c-family/c-pretty-print.cc.jj 2022-02-14 13:14:39.037128630 +0100 +++ gcc/c-family/c-pretty-print.cc 2022-03-16 11:16:54.957658064 +0100 @@ -1889,6 +1889,12 @@ c_fold_indirect_ref_for_warn (location_t = wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (field))); if (upos <= off && off < upos + el_sz) { + /* The C++ pretty printers print scope of the FIELD_DECLs, + so punt if it is something that can't be printed. */ + if (c_dialect_cxx ()) + if (tree scope = get_containing_scope (field)) + if (TYPE_P (scope) && TYPE_NAME (scope) == NULL_TREE) + break; tree cop = build3_loc (loc, COMPONENT_REF, TREE_TYPE (field), op, field, NULL_TREE); off = off - upos; --- gcc/testsuite/g++.dg/warn/pr101515.C.jj 2022-03-16 11:19:09.004806778 +0100 +++ gcc/testsuite/g++.dg/warn/pr101515.C 2022-03-16 11:24:35.136302673 +0100 @@ -0,0 +1,18 @@ +// PR c++/101515 +// { dg-do compile } +// { dg-options "-O1 -Wuninitialized" } + +struct S { int j; }; +struct T : public S { virtual void h () {} }; +struct U { void (*ptr) (); }; +typedef void (S::*sp) (); + +int +main () +{ + T t; + sp x; + U *xp = (U *) &x; + if (xp->ptr != ((void (*) ()) (sizeof (void *)))) // { dg-warning "is used uninitialized" } + return 1; +}