Fix crash in quirk_rust_enum
[binutils-gdb.git] / gdb / dwarf2read.c
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)