From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH] Fix Rust unsized2.exp failures with newer Rust compiler
Date: Sat, 31 Oct 2026 14:24:05 -0600 [thread overview]
Message-ID: <20261031202405.4002049-1-tom@tromey.com> (raw)
Newer versions of the Rust compiler changed to emit an array type as
the trailing type of an unsized object. That is, now they look
somewhat like a struct using the C "struct hack". Previously, this
trailing field was emitted using the element type.
This change caused some gdb failures in gdb.rust/unsized2.exp.
This patch fixes the problem. It uses a heuristic to decide which
type to use. I believe the heuristic should work because any possibly
concrete array type in the final slot here should have a length.
I tested this with rustc 1.61 (minimum version for unsized2.exp, uses
the element type) and rustc 1.99 (has the fix, uses an array type). I
don't know precisely which version of rustc introduced the fix; it
seemed like a pain to find out and I don't think it matters.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34344
---
gdb/rust-lang.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 9c2a4c4c811..9b62cf8b687 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -302,7 +302,17 @@ rewrite_slice_type (struct type *in_type, struct type **new_type,
{
if (additional_length == nullptr)
return true;
- rewritten = lookup_array_range_type (field_type, 0, bound);
+ /* Rust changed to emit an array type here. This is an
+ improvement, but it puts gdb in a bind, because which variant
+ is in use isn't readily knowable here. We use the heuristic
+ that if the trailing member is an array without an upper
+ bound, then it is "new style". */
+ if (field_type->code () == TYPE_CODE_ARRAY
+ && field_type->bounds ()->high.kind () == PROP_UNDEFINED)
+ rewritten = lookup_array_range_type (field_type->target_type (),
+ 0, bound);
+ else
+ rewritten = lookup_array_range_type (field_type, 0, bound);
*additional_length = rewritten->length ();
}
else
--
2.49.0
next reply other threads:[~2026-10-31 20:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-31 20:24 Tom Tromey [this message]
2026-11-23 19:09 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261031202405.4002049-1-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox