Browse Source

Fix big int shifts of 0

gingerBill 6 years ago
parent
commit
dfd7a194ed
2 changed files with 16 additions and 0 deletions
  1. 14 0
      src/big_int.cpp
  2. 2 0
      src/types.cpp

+ 14 - 0
src/big_int.cpp

@@ -554,6 +554,16 @@ void big_int_sub(BigInt *dst, BigInt const *x, BigInt const *y) {
 void big_int_shl(BigInt *dst, BigInt const *x, BigInt const *y) {
 	GB_ASSERT(!y->neg);
 
+	if (x->len == 0) {
+		big_int_from_u64(dst, 0);
+		return;
+	}
+
+	if (x->len == 1 && x->d.word == 0) {
+		big_int_from_u64(dst, 0);
+		return;
+	}
+
 	if (y->len == 0) {
 		big_int_init(dst, x);
 		return;
@@ -605,6 +615,10 @@ void big_int_shr(BigInt *dst, BigInt const *x, BigInt const *y) {
 		big_int_from_u64(dst, 0);
 		return;
 	}
+	if (x->len == 1 && x->d.word == 0) {
+		big_int_from_u64(dst, 0);
+		return;
+	}
 
 	if (y->len == 0) {
 		big_int_init(dst, x);

+ 2 - 0
src/types.cpp

@@ -712,6 +712,8 @@ bool is_type_numeric(Type *t) {
 	t = base_type(t);
 	if (t->kind == Type_Basic) {
 		return (t->Basic.flags & BasicFlag_Numeric) != 0;
+	} else if (t->kind == Type_Enum) {
+		return is_type_numeric(t->Enum.base_type);
 	}
 	// TODO(bill): Should this be here?
 	if (t->kind == Type_Array) {