Browse Source

Fix `bit_set` range

gingerBill 7 years ago
parent
commit
79a3c0b36c
2 changed files with 7 additions and 16 deletions
  1. 4 14
      src/check_type.cpp
  2. 3 2
      src/types.cpp

+ 4 - 14
src/check_type.cpp

@@ -708,24 +708,14 @@ void check_bit_set_type(CheckerContext *ctx, Type *type, Ast *node) {
 			}
 			ExactValue value = exact_value_to_integer(e->Constant.value);
 			GB_ASSERT(value.kind == ExactValue_Integer);
-			BigInt v = value.value_integer;
-
-
-			if (big_int_cmp(&v, &BIG_INT_ZERO) < 0) {
-				error(bs->base_type, "Negative enum values are not allowed in a bit_set");
-				return;
-			}
-
-			if (big_int_cmp(&v, &v64) >= 0) {
-				error(bs->base_type, "Enum values overe 64 are not allowed in a bit_set");
-				return;
-			}
-
-			i64 x = big_int_to_i64(&v);
+			i64 x = big_int_to_i64(&value.value_integer);
 			min_value = gb_min(min_value, x);
 			max_value = gb_max(max_value, x);
 		}
 
+		if (max_value - min_value > 64) {
+			error(bs->base_type, "bit_set range is greater than 64 bits");
+		}
 
 		type->BitSet.min = min_value;
 		type->BitSet.max = max_value;

+ 3 - 2
src/types.cpp

@@ -2075,7 +2075,8 @@ i64 type_align_of_internal(Type *t, TypePath *path) {
 		if (bits <= 16) return 2;
 		if (bits <= 32) return 4;
 		if (bits <= 64) return 8;
-		GB_PANIC("unknown bit_set size");
+		return 8;
+
 	}
 	}
 
@@ -2301,7 +2302,7 @@ i64 type_size_of_internal(Type *t, TypePath *path) {
 		if (bits <= 16) return 2;
 		if (bits <= 32) return 4;
 		if (bits <= 64) return 8;
-		GB_PANIC("unknown bit_set size");
+		return 8;
 	}
 	}