- /* This function currently only works for ranges with two defined,
- constant bounds. */
- if (type->bounds ()->low.kind () != PROP_CONST
- || type->bounds ()->high.kind () != PROP_CONST)
+ {
+ /* This function only works for ranges with a constant low bound. */
+ if (type->bounds ()->low.kind () != PROP_CONST)
+ return {};
+
+ LONGEST low = type->bounds ()->low.const_val ();
+
+ if (TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_ENUM)
+ {
+ gdb::optional<LONGEST> low_pos
+ = discrete_position (TYPE_TARGET_TYPE (type), low);
+
+ if (low_pos.has_value ())
+ low = *low_pos;
+ }
+
+ return low;
+ }
+
+ case TYPE_CODE_ENUM:
+ {
+ if (type->num_fields () > 0)
+ {
+ /* The enums may not be sorted by value, so search all
+ entries. */
+ LONGEST low = TYPE_FIELD_ENUMVAL (type, 0);
+
+ for (int i = 0; i < type->num_fields (); i++)
+ {
+ if (TYPE_FIELD_ENUMVAL (type, i) < low)
+ low = TYPE_FIELD_ENUMVAL (type, i);
+ }
+
+ /* Set unsigned indicator if warranted. */
+ if (low >= 0)
+ type->set_is_unsigned (true);
+
+ return low;
+ }
+ else
+ return 0;
+ }
+
+ case TYPE_CODE_BOOL:
+ return 0;
+
+ case TYPE_CODE_INT:
+ if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */