Fix crash in quirk_rust_enum
authorTom Tromey <tom@tromey.com>
Thu, 29 Mar 2018 17:49:59 +0000 (11:49 -0600)
committerTom Tromey <tom@tromey.com>
Tue, 17 Apr 2018 19:37:44 +0000 (13:37 -0600)
I noticed that quirk_rust_enum can crash when presented with a union
whose fields are all scalar types.

This patch adds a new test case and fixes the bug.

Regression tested on Fedora 26 x86-64.

2018-04-17  Tom Tromey  <tom@tromey.com>

* dwarf2read.c (quirk_rust_enum): Handle unions correctly.

2018-04-17  Tom Tromey  <tom@tromey.com>

* gdb.rust/simple.rs (Union): New type.
(main): New local "u".
* gdb.rust/simple.exp (test_one_slice): Add new test case.

gdb/ChangeLog
gdb/dwarf2read.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.rust/simple.exp
gdb/testsuite/gdb.rust/simple.rs

index 2720af9e4b99888946b9aa82fc7a9face1677608..35072e85db02817dcd58117ae9fba28daae043b4 100644 (file)
@@ -1,3 +1,7 @@
+2018-04-17  Tom Tromey  <tom@tromey.com>
+
+       * dwarf2read.c (quirk_rust_enum): Handle unions correctly.
+
 2018-04-17  Andreas Arnez  <arnez@linux.vnet.ibm.com>
 
        * symtab.c (print_symbol_info): Skip printing filename and line
index 9c9dcee058cf37fa23797a668d181ee69c132b80..0d3af00c463d752608bb9e8fb809a9312de3b6d4 100644 (file)
@@ -9989,9 +9989,15 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
        {
          disr_type = TYPE_FIELD_TYPE (type, i);
 
-         if (TYPE_NFIELDS (disr_type) == 0)
+         if (TYPE_CODE (disr_type) != TYPE_CODE_STRUCT)
+           {
+             /* All fields of a true enum will be structs.  */
+             return;
+           }
+         else if (TYPE_NFIELDS (disr_type) == 0)
            {
              /* Could be data-less variant, so keep going.  */
+             disr_type = nullptr;
            }
          else if (strcmp (TYPE_FIELD_NAME (disr_type, 0),
                           "RUST$ENUM$DISR") != 0)
index 749c01af814352385105c4b9a3867107f44b6606..68ae3d7b5a267dd9018b452460dbbf4fe053c753 100644 (file)
@@ -1,3 +1,9 @@
+2018-04-17  Tom Tromey  <tom@tromey.com>
+
+       * gdb.rust/simple.rs (Union): New type.
+       (main): New local "u".
+       * gdb.rust/simple.exp (test_one_slice): Add new test case.
+
 2018-04-16  Andreas Arnez  <arnez@linux.vnet.ibm.com>
 
        * gdb.base/dbx.exp (test_whereis): Adjust regexp to added line
index 846abe11a4d6ca1e693d7c8bf37453ed17509147..d70de3383504c0d71f02df6e1ad47d988db17415 100644 (file)
@@ -277,6 +277,7 @@ gdb_test "print parametrized.next.val" \
 gdb_test "print parametrized" \
     " = simple::ParametrizedStruct<i32> \\{next: simple::ParametrizedEnum<\[a-z:\]*Box<simple::ParametrizedStruct<i32>>>::Val\\{val: $hex\\}, value: 0\\}"
 
+gdb_test "print u" " = simple::Union {f1: -1, f2: 255}"
 
 load_lib gdb-python.exp
 if {[skip_python_tests]} {
index b2b5dfe0f6b2e7914b76c47ae20b38b1bc8ada94..e5bbe521226cc4869a7d4cf525cf02abf5b1030e 100644 (file)
@@ -80,6 +80,11 @@ struct ParametrizedStruct<T> {
     value: T
 }
 
+union Union {
+    f1: i8,
+    f2: u8,
+}
+
 fn main () {
     let a = ();
     let b : [i32; 0] = [];
@@ -153,6 +158,8 @@ fn main () {
         value: 0,
     };
 
+    let u = Union { f2: 255 };
+
     println!("{}, {}", x.0, x.1);        // set breakpoint here
     println!("{}", diff2(92, 45));
     empty();
This page took 0.040677 seconds and 4 git commands to generate.