Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Fix Rust unsized2.exp failures with newer Rust compiler
@ 2026-10-31 20:24 Tom Tromey
  2026-11-23 19:09 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2026-10-31 20:24 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-23 19:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-31 20:24 [PATCH] Fix Rust unsized2.exp failures with newer Rust compiler Tom Tromey
2026-11-23 19:09 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox