From patchwork Wed Sep 17 15:39:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 120437 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B28C2385801B for ; Wed, 17 Sep 2025 15:43:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B28C2385801B X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 12E64385743A for ; Wed, 17 Sep 2025 15:39:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 12E64385743A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 12E64385743A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758123560; cv=none; b=W2UjgNjiS3133k6toE3q8sc6KU9p7giEwdpWcDHvbUi+e/1vOduFQWhtrOdhC0nV+4Hc8tBVAw/wsU27KP764p9INW9q2awys8U+QIGO1NND3MZQ6KiFPtFl30U69iMGJspVdDSQtOqsjDDlldM6ALOEiu0Ps2DVBrmU9i+3A8M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758123560; c=relaxed/simple; bh=gpuIjREzyqI7o4pbOEuGVGj1OlJleE7CWRtMUmHAVpU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=r/lR9HMhcmzSYuTkKus19vyGjd1/5au0w0zu3Ny+Wji1OkWCQGrfYyQcUDUK/XpFqZO5GXHtv9y8+i3RVtOnnQrXtgCH7nvN9zzuKNx2CY1bLbVt3ZIZ6IKxbbyhEznweO8bhx4YRXeRgiXcsews2SrKN2N16kEpGORb2qvJrAI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 12E64385743A Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3B02A267F; Wed, 17 Sep 2025 08:39:11 -0700 (PDT) Received: from fdebian.localdomain (unknown [10.1.36.163]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 920CC3F694; Wed, 17 Sep 2025 08:39:18 -0700 (PDT) From: Yury Khrustalev To: gcc-patches@gcc.gnu.org Cc: tamar.christina@arm.com, srinath.parvathaneni@arm.com, tejas.belagod@arm.com, jakub@redhat.com Subject: [PATCH] dwarf: Save bit stride information array type entry [PR121964] Date: Wed, 17 Sep 2025 16:39:12 +0100 Message-ID: <20250917153912.3187098-1-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_NONE, TXREP 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~patchwork=sourceware.org@gcc.gnu.org Lack of DW_AT_bit_stride in a DW_TAG_array_type entry causes GDB to infer incorrect element size for vector types. The causes incorrect display of SVE predicate variables as well as out of bounds memory access when reading contents of SVE predicates from memory in GDB. PR debug/121964 gcc/ * dwarf2out.cc (base_type_die): add DW_AT_bit_size attribute for boolean types. (gen_array_type_die): add DW_AT_bit_stride attribute for array types based on element type bit precision for integer and boolean element types. gcc/testsuite/ * g++.target/aarch64/sve/dwarf-bit-stride.C: New test. * gcc.target/aarch64/sve/dwarf-bit-stride.c: New test. --- Passes regression on aarch64. OK for trunk? base-commit: 282c1e682e0 --- gcc/dwarf2out.cc | 11 ++++++++++- .../g++.target/aarch64/sve/dwarf-bit-stride.C | 15 +++++++++++++++ .../gcc.target/aarch64/sve/dwarf-bit-stride.c | 15 +++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.target/aarch64/sve/dwarf-bit-stride.C create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/dwarf-bit-stride.c diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index 0bd8474bc37..aaaa578ce56 100644 --- a/gcc/dwarf2out.cc +++ b/gcc/dwarf2out.cc @@ -13360,7 +13360,8 @@ base_type_die (tree type, bool reverse) add_AT_unsigned (base_type_result, DW_AT_byte_size, int_size_in_bytes (type)); add_AT_unsigned (base_type_result, DW_AT_encoding, encoding); - if (TREE_CODE (type) == BITINT_TYPE) + if (TREE_CODE (type) == BITINT_TYPE + || TREE_CODE (type) == BOOLEAN_TYPE) add_AT_unsigned (base_type_result, DW_AT_bit_size, TYPE_PRECISION (type)); if (need_endianity_attribute_p (reverse)) @@ -22765,6 +22766,14 @@ gen_array_type_die (tree type, dw_die_ref context_die) /* Add representation of the type of the elements of this array type and emit the corresponding DIE if we haven't done it already. */ element_type = TREE_TYPE (type); + + /* Add bit stride information so that elements can be correctly + read and displayed by a debugger. */ + if (TREE_CODE (element_type) == BITINT_TYPE + || TREE_CODE (element_type) == BOOLEAN_TYPE) + add_AT_unsigned (array_die, + DW_AT_bit_stride, TYPE_PRECISION (element_type)); + if (collapse_nested_arrays) while (TREE_CODE (element_type) == ARRAY_TYPE) { diff --git a/gcc/testsuite/g++.target/aarch64/sve/dwarf-bit-stride.C b/gcc/testsuite/g++.target/aarch64/sve/dwarf-bit-stride.C new file mode 100644 index 00000000000..bbc967c7ffd --- /dev/null +++ b/gcc/testsuite/g++.target/aarch64/sve/dwarf-bit-stride.C @@ -0,0 +1,15 @@ +/* { dg-do compile { target aarch64_asm_sve_ok } } */ +// { dg-options "-g -dA" } +// { dg-final { scan-assembler-times "DW_AT_bit_stride" 2 } } +// { dg-final { scan-assembler-times "DW_AT_GNU_vector" 2 } } +// { dg-final { scan-assembler-times "DW_TAG_array_type" 2 } } + +#include + +void fun () +{ + volatile svbool_t pred8 = svwhilelt_b8_u32 (0u, 1u); + volatile svbool_t pred16 = svwhilelt_b16_u32 (0u, 3u); + volatile svbool_t pred32 = svwhilelt_b32_u32 (0u, 7u); + volatile svbool_t pred64 = svwhilelt_b64_u32 (0u, 11u); +} diff --git a/gcc/testsuite/gcc.target/aarch64/sve/dwarf-bit-stride.c b/gcc/testsuite/gcc.target/aarch64/sve/dwarf-bit-stride.c new file mode 100644 index 00000000000..bbc967c7ffd --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/dwarf-bit-stride.c @@ -0,0 +1,15 @@ +/* { dg-do compile { target aarch64_asm_sve_ok } } */ +// { dg-options "-g -dA" } +// { dg-final { scan-assembler-times "DW_AT_bit_stride" 2 } } +// { dg-final { scan-assembler-times "DW_AT_GNU_vector" 2 } } +// { dg-final { scan-assembler-times "DW_TAG_array_type" 2 } } + +#include + +void fun () +{ + volatile svbool_t pred8 = svwhilelt_b8_u32 (0u, 1u); + volatile svbool_t pred16 = svwhilelt_b16_u32 (0u, 3u); + volatile svbool_t pred32 = svwhilelt_b32_u32 (0u, 7u); + volatile svbool_t pred64 = svwhilelt_b64_u32 (0u, 11u); +}