Fix Rust enum test failures
authorTom Tromey <tom@tromey.com>
Wed, 28 Feb 2018 15:49:51 +0000 (08:49 -0700)
committerTom Tromey <tom@tromey.com>
Thu, 1 Mar 2018 16:34:51 +0000 (09:34 -0700)
Pedro pointed out that some Rust tests were failing after the recent
enum change.  I was able to reproduce this even with the most current
Rust compiler -- no test was failing, but rather the gdb internal
error was causing an "untested" result, which I didn't notice.

The internal error is caused by a bad assertion in
alloc_discriminant_info.  This happened because, in an earlier version
of the patch, the discriminant could only appear at index 0.  However,
it can now appear anywhere.  This patch fixes the assertion in the
obvious way, and adds a second assertion to ensure that the
discriminant is also correct.

Fixing this revealed a real failure, which was caused by using the
wrong base name when computing the name of a univariant enum's sole
member.  This is also fixed here.

Tested by running the gdb.rust tests with rustc 1.23 and
double-checking the summary:

    # of expected passes 276

Note that if you try this yourself, it is still possible to get an
"untested" result from traits.exp if your Rust compiler is old enough.

2018-03-01  Tom Tromey  <tom@tromey.com>

* dwarf2read.c (alloc_discriminant_info): Fix default_index
assertion.  Add assertion for discriminant_index.
(quirk_rust_enum): Use correct base type name in univariant case.

gdb/ChangeLog
gdb/dwarf2read.c

index 52079b4313100e648453268494b1b4b821fe0ca6..5b911af3fd81640ea79f85353d8e35dee4202a54 100644 (file)
@@ -1,3 +1,9 @@
+2018-03-01  Tom Tromey  <tom@tromey.com>
+
+       * dwarf2read.c (alloc_discriminant_info): Fix default_index
+       assertion.  Add assertion for discriminant_index.
+       (quirk_rust_enum): Use correct base type name in univariant case.
+
 2018-03-01  Simon Marchi  <simon.marchi@ericsson.com>
 
        * record.c (get_call_history_modifiers): Return a
index 9825117fa7a1e5919dc6adf470a14736252cbf37..5827ab446caf14f65209a551b10517f24e9984b6 100644 (file)
@@ -10364,8 +10364,11 @@ alloc_discriminant_info (struct type *type, int discriminant_index,
                         int default_index)
 {
   gdb_assert (TYPE_CODE (type) == TYPE_CODE_UNION);
+  gdb_assert (discriminant_index == -1
+             || (discriminant_index >= 0
+                 && discriminant_index < TYPE_NFIELDS (type)));
   gdb_assert (default_index == -1
-             || (default_index > 0 && default_index < TYPE_NFIELDS (type)));
+             || (default_index >= 0 && default_index < TYPE_NFIELDS (type)));
 
   TYPE_FLAG_DISCRIMINATED_UNION (type) = 1;
 
@@ -10518,7 +10521,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
       TYPE_FIELD_NAME (union_type, 0) = variant_name;
       TYPE_NAME (field_type)
        = rust_fully_qualify (&objfile->objfile_obstack,
-                             TYPE_NAME (field_type), variant_name);
+                             TYPE_NAME (type), variant_name);
 
       /* Install the union in the outer struct type.  */
       TYPE_NFIELDS (type) = 1;
This page took 0.039926 seconds and 4 git commands to generate.