From patchwork Fri Feb 16 19:52:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 202344 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp750858dyb; Fri, 16 Feb 2024 11:53:15 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWUz66+GthMeMHCvcK3VmmWuoSpe8sd+KaNr0vPragb/CToQWxKK8NFaCXtdyChfjAxEz//wUEEJ4NM+73CLcW/zHnMnA== X-Google-Smtp-Source: AGHT+IGGd5xRCxX1Ud7U8k/9nmpoZlKAhRlAKHnvRr4oWSdZxxKBHqbSJPc3yXUwOXIwWmiONlVe X-Received: by 2002:ac8:5c8e:0:b0:42d:edad:2d08 with SMTP id r14-20020ac85c8e000000b0042dedad2d08mr680099qta.51.1708113195036; Fri, 16 Feb 2024 11:53:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708113195; cv=pass; d=google.com; s=arc-20160816; b=n/OjeOFuSeEx+O5Q4dmgeazB0RXwSGry49lafINRc5SZYO5U4RV2AGibVjo9sX+2RN 9JwvRYdLi4QNVXLol6f2li1NsPPLNgN7Hr6ECkT0/64uZdSAWzOaROzicPDlkALFgXMF 5P2AKoSkD6sfQnRWo0O9e8D4HESVQevVOAWfmuvGejk1PZjj+3g6i5FOfscD2WaglWh3 xySjrL5dK0xP/dbSwLUTUWCr+Pl8lOdYVa4cSd1c16mDkXDfKftBGOgVSc3qBXgB9Rik J1QAKimMPoQ2SMsKdV5Y5C8JY8JoCB7uneKpXcTIn6EMQNavH2C3JYe6vPoc3ACTSd7H PwIw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition:in-reply-to :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=OUbkWJ5Jdwze+/5Jjy/DF7IDiTh4ssnw5s8wEG1uDRY=; fh=0xZT+NBKSeH8qOu04/61f1ZGePpF4jF/gxp331YE14k=; b=FyqHFMfeKWQq/f+K+ReJ0g63UptZsoCJIwLr8L88EDPe/ZeFapcG51MpT6fKJ7IItR qBZd2R4mZV+w6EwoVBz3X8dfkIjDRpyFALQ0/7HBaXJtPVnPsCls6NGyBirn0Cao/Orm evSQ07PCfJaTsP2S90OHq9ZHV4SmgqaJytVv9TK+ClCMGI8gi5Iz/XGGXIKHMZQKJ8ZW 4GH+ehCcU9dswSjbvAZzDbXVrhaRqEc2tmGadmMvDnB/g6mDJHR3THWjf/cPoAXM8GU2 vdv2YTMDTd2jIOWN9jgDanx8JwFguwkL+07XBSoRRpv1en67mdQbskKm6Wgm3HbUVdNw Sn8w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VT8hwEvx; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u3-20020ac858c3000000b0042c189b36c8si593335qta.599.2024.02.16.11.53.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 11:53:15 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VT8hwEvx; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B7D49385782F for ; Fri, 16 Feb 2024 19:53:14 +0000 (GMT) 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 6DD5C3857B8B for ; Fri, 16 Feb 2024 19:52:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6DD5C3857B8B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6DD5C3857B8B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708113160; cv=none; b=DWHFBxZ/kWbX1HE/R/mfOfUimBWfF5pYYQjNFB8pIPQWGzelYAyJgZXAP6kMwmkkaPrInx2YiuR8Ipce3ccVNXDab3GYzzZKb7ES6I/H8lvm8w+NG7Rv3QRxbqDU/UXxh5yGq2cWPwq6mzvUWQk3b48DIUjfQW3apGugKdLMI9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708113160; c=relaxed/simple; bh=9h32f9qCkEwGtVMi7EjwwTRahx/xNT7JRRWWuBBnVLY=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=YUUvd+Vi0SbD8ypHmw7mzgWvkue9dUWs52ZZfVl0FggBUFG+SanslTG3M6RgD0dyxF2Oay0QttmETF/Gww1zAs1E8CtlEe3H42ysy+FeM78Cq9yfSE+5ENKr1z25GXa4uir9BsG/iydCa4HLqIkoKDX2Di1bsl1dGQ1KI8YKOtg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708113157; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=OUbkWJ5Jdwze+/5Jjy/DF7IDiTh4ssnw5s8wEG1uDRY=; b=VT8hwEvxvX5p5a5zPRkH3IaAPMEYINveDqVHtFef4qyzCcI6Z5QDCYHYBgigGK1LB3YG6M kPH84veua0KbinOrRRkbfOwxXcOgDUrZFJCQKldk6It/CNAuAyuaTxDvRR0jt1fgag/5TR ee/dr/UUQr5b93IJUepjWeA8OuUK9nE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-331-7gEhC-4nN4yvV-IIGeGhlg-1; Fri, 16 Feb 2024 14:52:35 -0500 X-MC-Unique: 7gEhC-4nN4yvV-IIGeGhlg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C927D1064C67 for ; Fri, 16 Feb 2024 19:52:34 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.8]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8A0CD401971E; Fri, 16 Feb 2024 19:52:34 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 41GJqWGL189557 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 20:52:32 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 41GJqVjT189556; Fri, 16 Feb 2024 20:52:31 +0100 Date: Fri, 16 Feb 2024 20:52:31 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] dwarf2out, v2: Emit DW_AT_export_symbols on anon unions/structs [PR113918] Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.6 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_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791086502093322115 X-GMAIL-MSGID: 1791086502093322115 On Fri, Feb 16, 2024 at 04:52:20PM +0100, Jakub Jelinek wrote: > On Fri, Feb 16, 2024 at 10:48:28AM -0500, Jason Merrill wrote: > > On 2/16/24 04:14, Jakub Jelinek wrote: > > > DWARF5 added DW_AT_export_symbols both for use on inline namespaces (where > > > we emit it), but also on anonymous unions/structs (and we didn't emit that > > > attribute there). > > > The following patch fixes it. > > > > Should this involve cp_decl_dwarf_attribute like the namespace handling? > > I wrote it in dwarf2out.cc because the same thing needs to be done for C and > C++ (admittedly dunno if other languages have something similar). > > Sure, it could be done in cp_decl_dwarf_attribute too but then it has to be > done in c_decl_dwarf_attribute which doesn't exist. Though, it is slightly > complicated by DW_AT_export_symbols not actually going on the DW_TAG_member > die but on the DW_TAG_{structure,class,union}_type which DW_TAG_member uses > as its DW_AT_type. But in order to ask the langhook, we likely need to pass > the FIELD_DECL and not the type... Anyway, here is a version of the patch that uses the langhook for it. So that the langhook isn't totally abused and for performance reasons too I've kept the DECL_NAME == NULL check on the dwarf2out.cc side and am calling it on the type rather than decl, because type is where the attribute should go. 2024-02-16 Jakub Jelinek PR debug/113918 gcc/ * dwarf2out.cc (gen_field_die): Emit DW_AT_export_symbols on anonymous unions or structs for -gdwarf-5 or -gno-strict-dwarf. gcc/c/ * c-tree.h (c_type_dwarf_attribute): Declare. * c-objc-common.h (LANG_HOOKS_TYPE_DWARF_ATTRIBUTE): Redefine. * c-objc-common.cc: Include dwarf2.h. (c_type_dwarf_attribute): New function. gcc/cp/ * cp-objcp-common.cc (cp_type_dwarf_attribute): Return 1 for DW_AT_export_symbols on anonymous structs or unions. gcc/testsuite/ * c-c++-common/dwarf2/pr113918.c: New test. Jakub --- gcc/dwarf2out.cc.jj 2024-02-15 13:54:29.284358101 +0100 +++ gcc/dwarf2out.cc 2024-02-16 20:38:19.718841259 +0100 @@ -25153,6 +25153,17 @@ gen_field_die (tree decl, struct vlr_con add_accessibility_attribute (decl_die, decl); + /* Add DW_AT_export_symbols to anonymous unions or structs. */ + if ((dwarf_version >= 5 || !dwarf_strict) && DECL_NAME (decl) == NULL_TREE) + if (tree type = member_declared_type (decl)) + if (lang_hooks.types.type_dwarf_attribute (TYPE_MAIN_VARIANT (type), + DW_AT_export_symbols) != -1) + { + dw_die_ref type_die = lookup_type_die (TYPE_MAIN_VARIANT (type)); + if (type_die && get_AT (type_die, DW_AT_export_symbols) == NULL) + add_AT_flag (type_die, DW_AT_export_symbols, 1); + } + /* Equate decl number to die, so that we can look up this decl later on. */ equate_decl_number_to_die (decl, decl_die); } --- gcc/c/c-tree.h.jj 2024-01-31 10:46:35.164761720 +0100 +++ gcc/c/c-tree.h 2024-02-16 20:43:45.993372908 +0100 @@ -731,6 +731,7 @@ extern bool c_warn_unused_global_decl (c extern void c_initialize_diagnostics (diagnostic_context *); extern bool c_var_mod_p (tree x, tree fn); extern alias_set_type c_get_alias_set (tree); +extern int c_type_dwarf_attribute (const_tree, int); /* in c-typeck.cc */ extern int in_alignof; --- gcc/c/c-objc-common.h.jj 2024-01-03 12:06:52.973862999 +0100 +++ gcc/c/c-objc-common.h 2024-02-16 20:42:21.073535465 +0100 @@ -119,6 +119,9 @@ static const scoped_attribute_specs *con #undef LANG_HOOKS_GIMPLIFY_EXPR #define LANG_HOOKS_GIMPLIFY_EXPR c_gimplify_expr +#undef LANG_HOOKS_TYPE_DWARF_ATTRIBUTE +#define LANG_HOOKS_TYPE_DWARF_ATTRIBUTE c_type_dwarf_attribute + #undef LANG_HOOKS_OMP_PREDETERMINED_SHARING #define LANG_HOOKS_OMP_PREDETERMINED_SHARING c_omp_predetermined_sharing --- gcc/c/c-objc-common.cc.jj 2024-01-03 12:06:53.213859637 +0100 +++ gcc/c/c-objc-common.cc 2024-02-16 20:45:24.649022305 +0100 @@ -30,6 +30,7 @@ along with GCC; see the file COPYING3. #include "gcc-rich-location.h" #include "stringpool.h" #include "attribs.h" +#include "dwarf2.h" static bool c_tree_printer (pretty_printer *, text_info *, const char *, int, bool, bool, bool, bool *, const char **); @@ -446,3 +447,25 @@ instantiation_dependent_expression_p (tr { return false; } + +/* Return -1 if dwarf ATTR shouldn't be added for TYPE, or the attribute + value otherwise. */ +int +c_type_dwarf_attribute (const_tree type, int attr) +{ + if (type == NULL_TREE) + return -1; + + switch (attr) + { + case DW_AT_export_symbols: + if (RECORD_OR_UNION_TYPE_P (type) && TYPE_NAME (type) == NULL_TREE) + return 1; + break; + + default: + break; + } + + return -1; +} --- gcc/cp/cp-objcp-common.cc.jj 2024-02-13 12:50:21.666846296 +0100 +++ gcc/cp/cp-objcp-common.cc 2024-02-16 20:40:51.374763528 +0100 @@ -410,6 +410,15 @@ cp_type_dwarf_attribute (const_tree type return 1; break; + case DW_AT_export_symbols: + if (RECORD_OR_UNION_TYPE_P (type)) + { + tree type_id = TYPE_IDENTIFIER (type); + if (type_id == NULL_TREE || IDENTIFIER_ANON_P (type_id)) + return 1; + } + break; + default: break; } --- gcc/testsuite/c-c++-common/dwarf2/pr113918.c.jj 2024-02-16 20:27:13.996961811 +0100 +++ gcc/testsuite/c-c++-common/dwarf2/pr113918.c 2024-02-16 20:27:13.996961811 +0100 @@ -0,0 +1,33 @@ +/* PR debug/113918 */ +/* { dg-do compile } */ +/* { dg-options "-gdwarf-5 -dA -fno-merge-debug-strings" } */ + +struct S { + union { + int i; + long long j; + }; + struct { + int k; + long long l; + }; + union { + int m; + long long n; + } u; + struct { + int o; + long long p; + } v; +} s; + +int +main () +{ + s.i = 1; + s.k = 2; + s.u.m = 3; + s.v.o = 4; +} + +/* { dg-final { scan-assembler-times "DW_AT_export_symbols" 4 } } */