From patchwork Tue Jan 9 20:17:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1884632 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=Fcw0JC61; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T8j0d2yrHz1yPh for ; Wed, 10 Jan 2024 07:17:53 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 710093857C5E for ; Tue, 9 Jan 2024 20:17:51 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 3A8A53858C39 for ; Tue, 9 Jan 2024 20:17:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3A8A53858C39 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3A8A53858C39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::333 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704831454; cv=none; b=IaK09KtlflEUMlgU4Jg/LSdAGTYA8zwJuJ1BZMJhsgL0Svc1+zlJUR4/9NDQSxW7VQMlH5wDfmSv1474XMN5thEGjv2JxUO5GkyuTlIPBLxZ/yNkgxHG+gP2epllYIIxP6SgZJNTH1jvUPuCEtH3ifwcw0O/BbzZn865nIFFa4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704831454; c=relaxed/simple; bh=ABR6y0A67eaC/4trA50DaSQHAt5Xj3/XKoXUhR16pm0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=rBVzLC84TODIofIslYkjyAJhdSJzoSZEPbpkttT7SU1hQ5YyEJt+mbdXwPke6Gs4TalqGVJ5kgpsGqHSsfqL+UnM83i4Er17fiQhLa0LiGmbBgyrOF80/vOziP0kZ7l4swCxAUjk0SPfRjS+OrFtAQrqFu70CSnpYEZfUoAlDiY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-40d4f5d902dso35721285e9.2 for ; Tue, 09 Jan 2024 12:17:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1704831451; x=1705436251; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ZwrEoObOWyqstqLrfSk/xVBmQdIzN5h8Zo63qrCzOzI=; b=Fcw0JC61wHaxyFGSJLL7EVNGOKLChXwJHP/86iao5nQACPJspORnb1UDD2OeIbNqsl EUgTvBSkw+JUyeRIXWKuKVSoV9dCwP+0D5ANygNxDVaZ5B5RiMnkjxRLAJ8gaRth6sRh NFfkA9h15LbXnXrqbUlTvNUJRpGEqkA+l1Ov2jAFh1jKf6NF1SIsgk2DXmJmXhOJjyrJ dNGQfrckKEH67M7s9A4prvKHBT2GgTPQWU1tE2ABrpNR0e2Fk0StCP44ptHu+PcV0qtz +duaVT2o0HhqKRP2NCeD0sibiQOpOrG4gxQT2E8hPKKqAESDQLxm/d30oB7K2AWM52IY SGlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704831451; x=1705436251; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZwrEoObOWyqstqLrfSk/xVBmQdIzN5h8Zo63qrCzOzI=; b=jAFZ26yd1cam62VHfg81rPy7FNhK2LE677K6BTBolx2UKLcceorCcqaG1JhIpbj9Po G7OFYnYzunhewenjBuAdi51ar16EihKQ0HzZOCYVPl00h2dI45W3JHpcj4HBg+vC33re dyPX11u4rCzWeneR/v2WBdI3aJtmJSEA24R5C2Yn3G3LUU4ULY8ldhNK5Dz23oXvzsII 8JHnwXLppfqcBVCAB9eUKqx8WmMno2ke8MGFCoEB245rRubyVONhdETa+5uuOQVNM0pO AH4NJ6yrXT3E9n/MPW2+3cOT9j3HKkPUwj9oXKlD1yyzihSIQFsB69FhnuisD/cH4Z7h n/dA== X-Gm-Message-State: AOJu0YxWpysl5oTaccah+17efphXnHJXNYDAlHvsqaflj+WOyqOrYZp3 IN+8ui5Q7R6lSAGQnC0HWGvs9BIMMKH8MAvTdX2xB1p4kQ== X-Google-Smtp-Source: AGHT+IErt8fQXcmzWrykOL43wdq4rb/1OgGCcLXuansLfGTRem8sYCG1WYmzY+VIR+AEcn+mvPO3Og== X-Received: by 2002:a05:600c:2051:b0:40e:43d3:ca55 with SMTP id p17-20020a05600c205100b0040e43d3ca55mr2628622wmg.163.1704831450984; Tue, 09 Jan 2024 12:17:30 -0800 (PST) Received: from fomalhaut.localnet ([2a01:e0a:8d5:d990:e654:e8ff:fe8f:2ce6]) by smtp.gmail.com with ESMTPSA id u4-20020adff884000000b003375cf3b17dsm3215105wrp.42.2024.01.09.12.17.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 12:17:30 -0800 (PST) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Cc: Tom Tromey Subject: [PATCH] Fix debug info for enumeration types with reverse Scalar_Storage_Order Date: Tue, 09 Jan 2024 21:17:29 +0100 Message-ID: <3238326.AJdgDx1Vlc@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi, this is not really a regression but the patch was written last week and is quite straightforward, so hopefully can nevertheless be OK. It implements the support of DW_AT_endianity for enumeration types because they are scalar and, therefore, reverse Scalar_Storage_Order is supported for them, but only when the -gstrict-dwarf switch is not passed because this is an extension. There is an associated GDB patch to be submitted by Tom to grok the new DWARF. Tested on x86-64/Linux, OK for the mainline? It may also help the GDB side to backport it for the upcoming 13.3 release. 2024-01-09 Eric Botcazou * dwarf2out.cc (modified_type_die): Extend the support of reverse storage order to enumeration types if -gstrict-dwarf is not passed. (gen_enumeration_type_die): Add REVERSE parameter and generate the DIE immediately after the existing one if it is true. (gen_tagged_type_die): Add REVERSE parameter and pass it in the call to gen_enumeration_type_die. (gen_type_die_with_usage): Add REVERSE parameter and pass it in the first recursive call as well as the call to gen_tagged_type_die. (gen_type_die): Add REVERSE parameter and pass it in the call to gen_type_die_with_usage. diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index 2f9010bc3cb..1c994bb8b9b 100644 --- a/gcc/dwarf2out.cc +++ b/gcc/dwarf2out.cc @@ -3940,7 +3940,7 @@ static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_re #if 0 static void gen_entry_point_die (tree, dw_die_ref); #endif -static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref); +static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref, bool); static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref); static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*); static void gen_unspecified_parameters_die (tree, dw_die_ref); @@ -3960,7 +3960,7 @@ static void gen_struct_or_union_type_die (tree, dw_die_ref, enum debug_info_usage); static void gen_subroutine_type_die (tree, dw_die_ref); static void gen_typedef_die (tree, dw_die_ref); -static void gen_type_die (tree, dw_die_ref); +static void gen_type_die (tree, dw_die_ref, bool = false); static void gen_block_die (tree, dw_die_ref); static void decls_for_scope (tree, dw_die_ref, bool = true); static bool is_naming_typedef_decl (const_tree); @@ -3976,8 +3976,10 @@ static struct dwarf_file_data * lookup_filename (const char *); static void retry_incomplete_types (void); static void gen_type_die_for_member (tree, tree, dw_die_ref); static void gen_generic_params_dies (tree); -static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage); -static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage); +static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage, + bool = false); +static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage, + bool = false); static void splice_child_die (dw_die_ref, dw_die_ref); static int file_info_cmp (const void *, const void *); static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *, var_loc_view, @@ -13665,8 +13667,11 @@ modified_type_die (tree type, int cv_quals, bool reverse, const int cv_qual_mask = (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE | TYPE_QUAL_RESTRICT | TYPE_QUAL_ATOMIC | ENCODE_QUAL_ADDR_SPACE(~0U)); - const bool reverse_base_type - = need_endianity_attribute_p (reverse) && is_base_type (type); + /* DW_AT_endianity is specified only for base types in the standard. */ + const bool reverse_type + = need_endianity_attribute_p (reverse) + && (is_base_type (type) + || (TREE_CODE (type) == ENUMERAL_TYPE && !dwarf_strict)); if (code == ERROR_MARK) return NULL; @@ -13726,9 +13731,9 @@ modified_type_die (tree type, int cv_quals, bool reverse, /* DW_AT_endianity doesn't come from a qualifier on the type, so it is dealt with specially: the DIE with the attribute, if it exists, is - placed immediately after the regular DIE for the same base type. */ + placed immediately after the regular DIE for the same type. */ if (mod_type_die - && (!reverse_base_type + && (!reverse_type || ((mod_type_die = mod_type_die->die_sib) != NULL && get_AT_unsigned (mod_type_die, DW_AT_endianity)))) return mod_type_die; @@ -13745,7 +13750,7 @@ modified_type_die (tree type, int cv_quals, bool reverse, tree dtype = TREE_TYPE (name); /* Skip the typedef for base types with DW_AT_endianity, no big deal. */ - if (qualified_type == dtype && !reverse_base_type) + if (qualified_type == dtype && !reverse_type) { tree origin = decl_ultimate_origin (name); @@ -13952,7 +13957,7 @@ modified_type_die (tree type, int cv_quals, bool reverse, mod_type_die = base_type_die (type, reverse); /* The DIE with DW_AT_endianity is placed right after the naked DIE. */ - if (reverse_base_type) + if (reverse_type) { dw_die_ref after_die = modified_type_die (type, cv_quals, false, context_die); @@ -13965,6 +13970,17 @@ modified_type_die (tree type, int cv_quals, bool reverse, } else { + /* The DIE with DW_AT_endianity is placed right after the naked DIE. */ + if (reverse_type) + { + dw_die_ref after_die + = modified_type_die (type, cv_quals, false, context_die); + gen_type_die (type, context_die, true); + gcc_assert (after_die->die_sib + && get_AT_unsigned (after_die->die_sib, DW_AT_endianity)); + return after_die->die_sib; + } + gen_type_die (type, context_die); /* We have to get the type_main_variant here (and pass that to the @@ -14034,7 +14050,7 @@ modified_type_die (tree type, int cv_quals, bool reverse, } } - if (qualified_type && !reverse_base_type) + if (qualified_type && !reverse_type) equate_type_number_to_die (qualified_type, mod_type_die); if (item_type) @@ -22824,19 +22840,31 @@ record_type_tag (tree type) /* Generate a DIE to represent an enumeration type. Note that these DIEs include all of the information about the enumeration values also. Each enumerated type name/value is listed as a child of the enumerated type - DIE. */ + DIE. REVERSE is true if the type is to be interpreted in the reverse + storage order wrt the target order. */ static dw_die_ref -gen_enumeration_type_die (tree type, dw_die_ref context_die) +gen_enumeration_type_die (tree type, dw_die_ref context_die, bool reverse) { dw_die_ref type_die = lookup_type_die (type); dw_die_ref orig_type_die = type_die; - if (type_die == NULL) + if (type_die == NULL || reverse) { - type_die = new_die (DW_TAG_enumeration_type, - scope_die_for (type, context_die), type); - equate_type_number_to_die (type, type_die); + /* The DIE with DW_AT_endianity is placed right after the naked DIE. */ + if (reverse) + { + gcc_assert (type_die); + dw_die_ref after_die = type_die; + type_die = new_die_raw (DW_TAG_enumeration_type); + add_child_die_after (context_die, type_die, after_die); + } + else + { + type_die = new_die (DW_TAG_enumeration_type, + scope_die_for (type, context_die), type); + equate_type_number_to_die (type, type_die); + } add_name_attribute (type_die, type_tag (type)); if ((dwarf_version >= 4 || !dwarf_strict) && ENUM_IS_SCOPED (type)) @@ -22848,6 +22876,9 @@ gen_enumeration_type_die (tree type, dw_die_ref context_die) TYPE_UNSIGNED (type) ? DW_ATE_unsigned : DW_ATE_signed); + if (reverse) + add_AT_unsigned (type_die, DW_AT_endianity, + BYTES_BIG_ENDIAN ? DW_END_little : DW_END_big); } else if (! TYPE_SIZE (type) || ENUM_IS_OPAQUE (type)) return type_die; @@ -26155,7 +26186,8 @@ gen_typedef_die (tree decl, dw_die_ref context_die) static void gen_tagged_type_die (tree type, dw_die_ref context_die, - enum debug_info_usage usage) + enum debug_info_usage usage, + bool reverse) { if (type == NULL_TREE || !is_tagged_type (type)) @@ -26200,8 +26232,8 @@ gen_tagged_type_die (tree type, { /* This might have been written out by the call to declare_in_namespace. */ - if (!TREE_ASM_WRITTEN (type)) - gen_enumeration_type_die (type, context_die); + if (!TREE_ASM_WRITTEN (type) || reverse) + gen_enumeration_type_die (type, context_die, reverse); } else gen_struct_or_union_type_die (type, context_die, usage); @@ -26215,7 +26247,7 @@ gen_tagged_type_die (tree type, static void gen_type_die_with_usage (tree type, dw_die_ref context_die, - enum debug_info_usage usage) + enum debug_info_usage usage, bool reverse) { struct array_descr_info info; @@ -26279,7 +26311,7 @@ gen_type_die_with_usage (tree type, dw_die_ref context_die, if (debug_type != NULL_TREE && debug_type != type) { - gen_type_die_with_usage (debug_type, context_die, usage); + gen_type_die_with_usage (debug_type, context_die, usage, reverse); return; } } @@ -26326,7 +26358,7 @@ gen_type_die_with_usage (tree type, dw_die_ref context_die, } } - if (TREE_ASM_WRITTEN (type)) + if (TREE_ASM_WRITTEN (type) && !reverse) { /* Variable-length types may be incomplete even if TREE_ASM_WRITTEN. For such types, fall through to @@ -26398,7 +26430,7 @@ gen_type_die_with_usage (tree type, dw_die_ref context_die, case RECORD_TYPE: case UNION_TYPE: case QUAL_UNION_TYPE: - gen_tagged_type_die (type, context_die, usage); + gen_tagged_type_die (type, context_die, usage, reverse); return; case VOID_TYPE: @@ -26450,11 +26482,11 @@ gen_type_die_with_usage (tree type, dw_die_ref context_die, } static void -gen_type_die (tree type, dw_die_ref context_die) +gen_type_die (tree type, dw_die_ref context_die, bool reverse) { if (type != error_mark_node) { - gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE); + gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE, reverse); if (flag_checking) { dw_die_ref die = lookup_type_die (type);