Browse Source

Add sanity casts for 32/64 bit correctness

gingerBill 4 years ago
parent
commit
76707e1d2f

+ 19 - 1
src/big_int.cpp

@@ -281,7 +281,25 @@ void big_int_mul(BigInt *dst, BigInt const *x, BigInt const *y) {
 
 
 u64 leading_zeros_u64(u64 x) {
 u64 leading_zeros_u64(u64 x) {
 #if defined(GB_COMPILER_MSVC)
 #if defined(GB_COMPILER_MSVC)
-	return __lzcnt64(x);
+	#if defined(GB_ARCH_64_BIT)
+		return __lzcnt64(x);
+	#else
+		u64 y, n;
+
+		n = 0;
+		y = x;
+	L:
+		if (x < 0) {
+			return n;
+		}
+		if (y == 0) {
+			return 64-n;
+		}
+		n++;
+		x <<= 1;
+		y >>= 1;
+		goto L;
+	#endif
 #else
 #else
 	return cast(u64)__builtin_clzll(cast(unsigned long long)x);
 	return cast(u64)__builtin_clzll(cast(unsigned long long)x);
 #endif
 #endif

+ 6 - 6
src/check_builtin.cpp

@@ -1120,7 +1120,7 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
 			// TODO(bill): Should I copy each of the entities or is this good enough?
 			// TODO(bill): Should I copy each of the entities or is this good enough?
 			gb_memmove_array(tuple->Tuple.variables.data, type->Struct.fields.data, variable_count);
 			gb_memmove_array(tuple->Tuple.variables.data, type->Struct.fields.data, variable_count);
 		} else if (is_type_array(type)) {
 		} else if (is_type_array(type)) {
-			isize variable_count = type->Array.count;
+			isize variable_count = cast(isize)type->Array.count;
 			array_init(&tuple->Tuple.variables, a, variable_count);
 			array_init(&tuple->Tuple.variables, a, variable_count);
 			for (isize i = 0; i < variable_count; i++) {
 			for (isize i = 0; i < variable_count; i++) {
 				tuple->Tuple.variables[i] = alloc_entity_array_elem(nullptr, blank_token, type->Array.elem, cast(i32)i);
 				tuple->Tuple.variables[i] = alloc_entity_array_elem(nullptr, blank_token, type->Array.elem, cast(i32)i);
@@ -1916,8 +1916,8 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
 		if (is_type_array(elem)) {
 		if (is_type_array(elem)) {
 			Type *old_array = base_type(elem);
 			Type *old_array = base_type(elem);
 			soa_struct = alloc_type_struct();
 			soa_struct = alloc_type_struct();
-			soa_struct->Struct.fields = array_make<Entity *>(heap_allocator(), old_array->Array.count);
-			soa_struct->Struct.tags = array_make<String>(heap_allocator(), old_array->Array.count);
+			soa_struct->Struct.fields = array_make<Entity *>(heap_allocator(), cast(isize)old_array->Array.count);
+			soa_struct->Struct.tags = array_make<String>(heap_allocator(), cast(isize)old_array->Array.count);
 			soa_struct->Struct.node = operand->expr;
 			soa_struct->Struct.node = operand->expr;
 			soa_struct->Struct.soa_kind = StructSoa_Fixed;
 			soa_struct->Struct.soa_kind = StructSoa_Fixed;
 			soa_struct->Struct.soa_elem = elem;
 			soa_struct->Struct.soa_elem = elem;
@@ -1933,7 +1933,7 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
 				str_lit("w")
 				str_lit("w")
 			};
 			};
 
 
-			for (i64 i = 0; i < old_array->Array.count; i++) {
+			for (isize i = 0; i < cast(isize)old_array->Array.count; i++) {
 				Type *array_type = alloc_type_array(old_array->Array.elem, count);
 				Type *array_type = alloc_type_array(old_array->Array.elem, count);
 				Token token = {};
 				Token token = {};
 				token.string = params_xyzw[i];
 				token.string = params_xyzw[i];
@@ -2891,7 +2891,7 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
 			if (bt->kind == Type_Proc) {
 			if (bt->kind == Type_Proc) {
 				count = bt->Proc.param_count;
 				count = bt->Proc.param_count;
 				if (index < count) {
 				if (index < count) {
-					param = bt->Proc.params->Tuple.variables[index];
+					param = bt->Proc.params->Tuple.variables[cast(isize)index];
 				}
 				}
 			}
 			}
 
 
@@ -2950,7 +2950,7 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
 			if (bt->kind == Type_Proc) {
 			if (bt->kind == Type_Proc) {
 				count = bt->Proc.result_count;
 				count = bt->Proc.result_count;
 				if (index < count) {
 				if (index < count) {
-					param = bt->Proc.results->Tuple.variables[index];
+					param = bt->Proc.results->Tuple.variables[cast(isize)index];
 				}
 				}
 			}
 			}
 
 

+ 1 - 1
src/check_expr.cpp

@@ -8118,7 +8118,7 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
 
 
 			o->mode = Addressing_Constant;
 			o->mode = Addressing_Constant;
 			o->type = t;
 			o->type = t;
-			o->value = exact_value_string(substring(s, indices[0], indices[1]));
+			o->value = exact_value_string(substring(s, cast(isize)indices[0], cast(isize)indices[1]));
 		}
 		}
 
 
 	case_end;
 	case_end;

+ 2 - 2
src/check_type.cpp

@@ -2218,7 +2218,7 @@ Type *make_soa_struct_internal(CheckerContext *ctx, Ast *array_typ_expr, Ast *el
 		soa_struct->Struct.scope = scope;
 		soa_struct->Struct.scope = scope;
 	} else if (is_type_array(elem)) {
 	} else if (is_type_array(elem)) {
 		Type *old_array = base_type(elem);
 		Type *old_array = base_type(elem);
-		field_count = old_array->Array.count;
+		field_count = cast(isize)old_array->Array.count;
 
 
 		soa_struct = alloc_type_struct();
 		soa_struct = alloc_type_struct();
 		soa_struct->Struct.fields = array_make<Entity *>(heap_allocator(), field_count+extra_field_count);
 		soa_struct->Struct.fields = array_make<Entity *>(heap_allocator(), field_count+extra_field_count);
@@ -2238,7 +2238,7 @@ Type *make_soa_struct_internal(CheckerContext *ctx, Ast *array_typ_expr, Ast *el
 			str_lit("w")
 			str_lit("w")
 		};
 		};
 
 
-		for (i64 i = 0; i < old_array->Array.count; i++) {
+		for (isize i = 0; i < cast(isize)old_array->Array.count; i++) {
 			Type *field_type = nullptr;
 			Type *field_type = nullptr;
 			if (soa_kind == StructSoa_Fixed) {
 			if (soa_kind == StructSoa_Fixed) {
 				GB_ASSERT(count >= 0);
 				GB_ASSERT(count >= 0);

+ 3 - 3
src/common.cpp

@@ -341,7 +341,7 @@ bool sub_overflow_u64(u64 x, u64 y, u64 *result) {
 }
 }
 
 
 void mul_overflow_u64(u64 x, u64 y, u64 *lo, u64 *hi) {
 void mul_overflow_u64(u64 x, u64 y, u64 *lo, u64 *hi) {
-#if defined(GB_COMPILER_MSVC)
+#if defined(GB_COMPILER_MSVC) && defined(GB_ARCH_64_BIT)
 	*lo = _umul128(x, y, hi);
 	*lo = _umul128(x, y, hi);
 #else
 #else
 	// URL(bill): https://stackoverflow.com/questions/25095741/how-can-i-multiply-64-bit-operands-and-get-128-bit-result-portably#25096197
 	// URL(bill): https://stackoverflow.com/questions/25095741/how-can-i-multiply-64-bit-operands-and-get-128-bit-result-portably#25096197
@@ -697,9 +697,9 @@ isize next_pow2_isize(isize n) {
 	n |= n >> 4;
 	n |= n >> 4;
 	n |= n >> 8;
 	n |= n >> 8;
 	n |= n >> 16;
 	n |= n >> 16;
-	if (gb_size_of(isize) == 8) {
+	#if defined(GB_ARCH_64_BIT)
 		n |= n >> 32;
 		n |= n >> 32;
-	}
+	#endif
 	n++;
 	n++;
 	return n;
 	return n;
 }
 }

+ 1 - 1
src/docs_writer.cpp

@@ -187,7 +187,7 @@ T *odin_doc_get_item(OdinDocWriter *w, OdinDocWriterItemTracker<T> *t, u32 index
 	if (w->state != OdinDocWriterState_Writing) {
 	if (w->state != OdinDocWriterState_Writing) {
 		return nullptr;
 		return nullptr;
 	}
 	}
-	GB_ASSERT(index < t->len);
+	GB_ASSERT(index < cast(u32)t->len);
 	uintptr data = cast(uintptr)w->data + cast(uintptr)(t->offset + gb_size_of(T)*index);
 	uintptr data = cast(uintptr)w->data + cast(uintptr)(t->offset + gb_size_of(T)*index);
 	return cast(T *)data;
 	return cast(T *)data;
 }
 }

+ 4 - 4
src/llvm_abi.cpp

@@ -565,7 +565,7 @@ namespace lbAbiAmd64SysV {
 	}
 	}
 
 
 	void unify(Array<RegClass> *cls, i64 i, RegClass const newv) {
 	void unify(Array<RegClass> *cls, i64 i, RegClass const newv) {
-		RegClass const oldv = (*cls)[i];
+		RegClass const oldv = (*cls)[cast(isize)i];
 		if (oldv == newv) {
 		if (oldv == newv) {
 			return;
 			return;
 		}
 		}
@@ -597,7 +597,7 @@ namespace lbAbiAmd64SysV {
 			}
 			}
 		}
 		}
 
 
-		(*cls)[i] = to_write;
+		(*cls)[cast(isize)i] = to_write;
 	}
 	}
 
 
 	void fixup(LLVMTypeRef t, Array<RegClass> *cls) {
 	void fixup(LLVMTypeRef t, Array<RegClass> *cls) {
@@ -606,7 +606,7 @@ namespace lbAbiAmd64SysV {
 		if (e > 2 && (lb_is_type_kind(t, LLVMStructTypeKind) ||
 		if (e > 2 && (lb_is_type_kind(t, LLVMStructTypeKind) ||
 		              lb_is_type_kind(t, LLVMArrayTypeKind) ||
 		              lb_is_type_kind(t, LLVMArrayTypeKind) ||
 		              lb_is_type_kind(t, LLVMVectorTypeKind))) {
 		              lb_is_type_kind(t, LLVMVectorTypeKind))) {
-			RegClass &oldv = (*cls)[i];
+			RegClass &oldv = (*cls)[cast(isize)i];
 			if (is_sse(oldv)) {
 			if (is_sse(oldv)) {
 				for (i++; i < e; i++) {
 				for (i++; i < e; i++) {
 					if (oldv != RegClass_SSEUp) {
 					if (oldv != RegClass_SSEUp) {
@@ -620,7 +620,7 @@ namespace lbAbiAmd64SysV {
 			}
 			}
 		} else {
 		} else {
 			while (i < e) {
 			while (i < e) {
-				RegClass &oldv = (*cls)[i];
+				RegClass &oldv = (*cls)[cast(isize)i];
 				if (oldv == RegClass_Memory) {
 				if (oldv == RegClass_Memory) {
 					all_mem(cls);
 					all_mem(cls);
 					return;
 					return;

+ 25 - 25
src/llvm_backend.cpp

@@ -491,7 +491,7 @@ void lb_addr_store(lbProcedure *p, lbAddr addr, lbValue value) {
 			field_count = elem_type->Struct.fields.count;
 			field_count = elem_type->Struct.fields.count;
 			break;
 			break;
 		case Type_Array:
 		case Type_Array:
-			field_count = elem_type->Array.count;
+			field_count = cast(isize)elem_type->Array.count;
 			break;
 			break;
 		}
 		}
 		for (isize i = 0; i < field_count; i++) {
 		for (isize i = 0; i < field_count; i++) {
@@ -1559,7 +1559,7 @@ LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
 				}
 				}
 			}
 			}
 
 
-			isize param_index = 0;
+			unsigned param_index = 0;
 			if (type->Proc.param_count != 0) {
 			if (type->Proc.param_count != 0) {
 				GB_ASSERT(type->Proc.params->kind == Type_Tuple);
 				GB_ASSERT(type->Proc.params->kind == Type_Tuple);
 				for_array(i, type->Proc.params->Tuple.variables) {
 				for_array(i, type->Proc.params->Tuple.variables) {
@@ -5714,7 +5714,7 @@ void lb_build_assign_stmt_array(lbProcedure *p, TokenKind op, lbAddr const &lhs,
 	} else {
 	} else {
 		lbValue y = lb_address_from_load_or_generate_local(p, rhs);
 		lbValue y = lb_address_from_load_or_generate_local(p, rhs);
 
 
-		auto loop_data = lb_loop_start(p, count, t_i32);
+		auto loop_data = lb_loop_start(p, cast(isize)count, t_i32);
 
 
 		lbValue a_ptr = lb_emit_array_ep(p, x, loop_data.idx);
 		lbValue a_ptr = lb_emit_array_ep(p, x, loop_data.idx);
 		lbValue b_ptr = lb_emit_array_ep(p, y, loop_data.idx);
 		lbValue b_ptr = lb_emit_array_ep(p, y, loop_data.idx);
@@ -6440,7 +6440,7 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc
 			if (count == 0) {
 			if (count == 0) {
 				return lb_const_nil(m, type);
 				return lb_const_nil(m, type);
 			}
 			}
-			count = gb_max(cl->max_count, count);
+			count = gb_max(cast(isize)cl->max_count, count);
 			Type *elem = base_type(type)->Slice.elem;
 			Type *elem = base_type(type)->Slice.elem;
 			Type *t = alloc_type_array(elem, count);
 			Type *t = alloc_type_array(elem, count);
 			lbValue backing_array = lb_const_value(m, t, value, allow_local);
 			lbValue backing_array = lb_const_value(m, t, value, allow_local);
@@ -6510,7 +6510,7 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc
 			isize width = 1;
 			isize width = 1;
 			String s = value.value_string;
 			String s = value.value_string;
 
 
-			LLVMValueRef *elems = gb_alloc_array(permanent_allocator(), LLVMValueRef, count);
+			LLVMValueRef *elems = gb_alloc_array(permanent_allocator(), LLVMValueRef, cast(isize)count);
 
 
 			for (i64 i = 0; i < count && offset < s.len; i++) {
 			for (i64 i = 0; i < count && offset < s.len; i++) {
 				width = gb_utf8_decode(s.text+offset, s.len-offset, &rune);
 				width = gb_utf8_decode(s.text+offset, s.len-offset, &rune);
@@ -6551,7 +6551,7 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc
 
 
 		lbValue single_elem = lb_const_value(m, elem, value, allow_local);
 		lbValue single_elem = lb_const_value(m, elem, value, allow_local);
 
 
-		LLVMValueRef *elems = gb_alloc_array(permanent_allocator(), LLVMValueRef, count);
+		LLVMValueRef *elems = gb_alloc_array(permanent_allocator(), LLVMValueRef, cast(isize)count);
 		for (i64 i = 0; i < count; i++) {
 		for (i64 i = 0; i < count; i++) {
 			elems[i] = single_elem.value;
 			elems[i] = single_elem.value;
 		}
 		}
@@ -6675,7 +6675,7 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc
 			}
 			}
 			if (cl->elems[0]->kind == Ast_FieldValue) {
 			if (cl->elems[0]->kind == Ast_FieldValue) {
 				// TODO(bill): This is O(N*M) and will be quite slow; it should probably be sorted before hand
 				// TODO(bill): This is O(N*M) and will be quite slow; it should probably be sorted before hand
-				LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, type->Array.count);
+				LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, cast(isize)type->Array.count);
 
 
 				isize value_index = 0;
 				isize value_index = 0;
 				for (i64 i = 0; i < type->Array.count; i++) {
 				for (i64 i = 0; i < type->Array.count; i++) {
@@ -6727,12 +6727,12 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc
 					}
 					}
 				}
 				}
 
 
-				res.value = lb_build_constant_array_values(m, type, elem_type, type->Array.count, values, allow_local);
+				res.value = lb_build_constant_array_values(m, type, elem_type, cast(isize)type->Array.count, values, allow_local);
 				return res;
 				return res;
 			} else {
 			} else {
 				GB_ASSERT_MSG(elem_count == type->Array.count, "%td != %td", elem_count, type->Array.count);
 				GB_ASSERT_MSG(elem_count == type->Array.count, "%td != %td", elem_count, type->Array.count);
 
 
-				LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, type->Array.count);
+				LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, cast(isize)type->Array.count);
 
 
 				for (isize i = 0; i < elem_count; i++) {
 				for (isize i = 0; i < elem_count; i++) {
 					TypeAndValue tav = cl->elems[i]->tav;
 					TypeAndValue tav = cl->elems[i]->tav;
@@ -6743,7 +6743,7 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc
 					values[i] = LLVMConstNull(lb_type(m, elem_type));
 					values[i] = LLVMConstNull(lb_type(m, elem_type));
 				}
 				}
 
 
-				res.value = lb_build_constant_array_values(m, type, elem_type, type->Array.count, values, allow_local);
+				res.value = lb_build_constant_array_values(m, type, elem_type, cast(isize)type->Array.count, values, allow_local);
 				return res;
 				return res;
 			}
 			}
 		} else if (is_type_enumerated_array(type)) {
 		} else if (is_type_enumerated_array(type)) {
@@ -6755,7 +6755,7 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc
 			}
 			}
 			if (cl->elems[0]->kind == Ast_FieldValue) {
 			if (cl->elems[0]->kind == Ast_FieldValue) {
 				// TODO(bill): This is O(N*M) and will be quite slow; it should probably be sorted before hand
 				// TODO(bill): This is O(N*M) and will be quite slow; it should probably be sorted before hand
-				LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, type->EnumeratedArray.count);
+				LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, cast(isize)type->EnumeratedArray.count);
 
 
 				isize value_index = 0;
 				isize value_index = 0;
 
 
@@ -6811,12 +6811,12 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc
 					}
 					}
 				}
 				}
 
 
-				res.value = lb_build_constant_array_values(m, type, elem_type, type->EnumeratedArray.count, values, allow_local);
+				res.value = lb_build_constant_array_values(m, type, elem_type, cast(isize)type->EnumeratedArray.count, values, allow_local);
 				return res;
 				return res;
 			} else {
 			} else {
 				GB_ASSERT_MSG(elem_count == type->EnumeratedArray.count, "%td != %td", elem_count, type->EnumeratedArray.count);
 				GB_ASSERT_MSG(elem_count == type->EnumeratedArray.count, "%td != %td", elem_count, type->EnumeratedArray.count);
 
 
-				LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, type->EnumeratedArray.count);
+				LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, cast(isize)type->EnumeratedArray.count);
 
 
 				for (isize i = 0; i < elem_count; i++) {
 				for (isize i = 0; i < elem_count; i++) {
 					TypeAndValue tav = cl->elems[i]->tav;
 					TypeAndValue tav = cl->elems[i]->tav;
@@ -6827,7 +6827,7 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc
 					values[i] = LLVMConstNull(lb_type(m, elem_type));
 					values[i] = LLVMConstNull(lb_type(m, elem_type));
 				}
 				}
 
 
-				res.value = lb_build_constant_array_values(m, type, elem_type, type->EnumeratedArray.count, values, allow_local);
+				res.value = lb_build_constant_array_values(m, type, elem_type, cast(isize)type->EnumeratedArray.count, values, allow_local);
 				return res;
 				return res;
 			}
 			}
 		} else if (is_type_simd_vector(type)) {
 		} else if (is_type_simd_vector(type)) {
@@ -6840,7 +6840,7 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc
 			}
 			}
 			GB_ASSERT(elem_type_can_be_constant(elem_type));
 			GB_ASSERT(elem_type_can_be_constant(elem_type));
 
 
-			isize total_elem_count = type->SimdVector.count;
+			isize total_elem_count = cast(isize)type->SimdVector.count;
 			LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, total_elem_count);
 			LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, total_elem_count);
 
 
 			for (isize i = 0; i < elem_count; i++) {
 			for (isize i = 0; i < elem_count; i++) {
@@ -6853,7 +6853,7 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc
 			for (isize i = elem_count; i < type->SimdVector.count; i++) {
 			for (isize i = elem_count; i < type->SimdVector.count; i++) {
 				values[i] = LLVMConstNull(et);
 				values[i] = LLVMConstNull(et);
 			}
 			}
-			for (isize i = 0; i< total_elem_count; i++) {
+			for (isize i = 0; i < total_elem_count; i++) {
 				values[i] = llvm_const_cast(values[i], et);
 				values[i] = llvm_const_cast(values[i], et);
 			}
 			}
 
 
@@ -7397,7 +7397,7 @@ lbValue lb_emit_arith_array(lbProcedure *p, TokenKind op, lbValue lhs, lbValue r
 
 
 		lbAddr res = lb_add_local_generated(p, type, false);
 		lbAddr res = lb_add_local_generated(p, type, false);
 
 
-		auto loop_data = lb_loop_start(p, count, t_i32);
+		auto loop_data = lb_loop_start(p, cast(isize)count, t_i32);
 
 
 		lbValue a_ptr = lb_emit_array_ep(p, x, loop_data.idx);
 		lbValue a_ptr = lb_emit_array_ep(p, x, loop_data.idx);
 		lbValue b_ptr = lb_emit_array_ep(p, y, loop_data.idx);
 		lbValue b_ptr = lb_emit_array_ep(p, y, loop_data.idx);
@@ -9477,9 +9477,9 @@ lbValue lb_soa_struct_len(lbProcedure *p, lbValue value) {
 	isize n = 0;
 	isize n = 0;
 	Type *elem = base_type(t->Struct.soa_elem);
 	Type *elem = base_type(t->Struct.soa_elem);
 	if (elem->kind == Type_Struct) {
 	if (elem->kind == Type_Struct) {
-		n = elem->Struct.fields.count;
+		n = cast(isize)elem->Struct.fields.count;
 	} else if (elem->kind == Type_Array) {
 	} else if (elem->kind == Type_Array) {
-		n = elem->Array.count;
+		n = cast(isize)elem->Array.count;
 	} else {
 	} else {
 		GB_PANIC("Unreachable");
 		GB_PANIC("Unreachable");
 	}
 	}
@@ -9509,9 +9509,9 @@ lbValue lb_soa_struct_cap(lbProcedure *p, lbValue value) {
 	isize n = 0;
 	isize n = 0;
 	Type *elem = base_type(t->Struct.soa_elem);
 	Type *elem = base_type(t->Struct.soa_elem);
 	if (elem->kind == Type_Struct) {
 	if (elem->kind == Type_Struct) {
-		n = elem->Struct.fields.count+1;
+		n = cast(isize)elem->Struct.fields.count+1;
 	} else if (elem->kind == Type_Array) {
 	} else if (elem->kind == Type_Array) {
-		n = elem->Array.count+1;
+		n = cast(isize)elem->Array.count+1;
 	} else {
 	} else {
 		GB_PANIC("Unreachable");
 		GB_PANIC("Unreachable");
 	}
 	}
@@ -11680,7 +11680,7 @@ lbValue lb_get_hasher_proc_for_type(lbModule *m, Type *type) {
 		auto args = array_make<lbValue>(permanent_allocator(), 2);
 		auto args = array_make<lbValue>(permanent_allocator(), 2);
 		lbValue elem_hasher = lb_get_hasher_proc_for_type(m, type->Array.elem);
 		lbValue elem_hasher = lb_get_hasher_proc_for_type(m, type->Array.elem);
 
 
-		auto loop_data = lb_loop_start(p, type->Array.count, t_i32);
+		auto loop_data = lb_loop_start(p, cast(isize)type->Array.count, t_i32);
 
 
 		data = lb_emit_conv(p, data, pt);
 		data = lb_emit_conv(p, data, pt);
 
 
@@ -11701,7 +11701,7 @@ lbValue lb_get_hasher_proc_for_type(lbModule *m, Type *type) {
 		auto args = array_make<lbValue>(permanent_allocator(), 2);
 		auto args = array_make<lbValue>(permanent_allocator(), 2);
 		lbValue elem_hasher = lb_get_hasher_proc_for_type(m, type->EnumeratedArray.elem);
 		lbValue elem_hasher = lb_get_hasher_proc_for_type(m, type->EnumeratedArray.elem);
 
 
-		auto loop_data = lb_loop_start(p, type->EnumeratedArray.count, t_i32);
+		auto loop_data = lb_loop_start(p, cast(isize)type->EnumeratedArray.count, t_i32);
 
 
 		data = lb_emit_conv(p, data, pt);
 		data = lb_emit_conv(p, data, pt);
 
 
@@ -13010,7 +13010,7 @@ lbValue lb_const_hash(lbModule *m, lbValue key, Type *key_type) {
 			unsigned len_indices[] = {1};
 			unsigned len_indices[] = {1};
 			LLVMValueRef data = LLVMConstExtractValue(key.value, data_indices, gb_count_of(data_indices));
 			LLVMValueRef data = LLVMConstExtractValue(key.value, data_indices, gb_count_of(data_indices));
 			LLVMValueRef len  = LLVMConstExtractValue(key.value, len_indices,  gb_count_of(len_indices));
 			LLVMValueRef len  = LLVMConstExtractValue(key.value, len_indices,  gb_count_of(len_indices));
-			isize length = LLVMConstIntGetSExtValue(len);
+			i64 length = LLVMConstIntGetSExtValue(len);
 			char const *text = nullptr;
 			char const *text = nullptr;
 			if (false && length != 0) {
 			if (false && length != 0) {
 				if (LLVMGetConstOpcode(data) != LLVMGetElementPtr) {
 				if (LLVMGetConstOpcode(data) != LLVMGetElementPtr) {
@@ -13021,7 +13021,7 @@ lbValue lb_const_hash(lbModule *m, lbValue key, Type *key_type) {
 				size_t ulength = 0;
 				size_t ulength = 0;
 				text = LLVMGetAsString(data, &ulength);
 				text = LLVMGetAsString(data, &ulength);
 				gb_printf_err("%td %td %s\n", length, ulength, text);
 				gb_printf_err("%td %td %s\n", length, ulength, text);
-				length = gb_min(length, cast(isize)ulength);
+				length = gb_min(length, cast(i64)ulength);
 			}
 			}
 			hash = fnv64a(text, cast(isize)length);
 			hash = fnv64a(text, cast(isize)length);
 		} else {
 		} else {

+ 1 - 1
src/microsoft_craziness.h

@@ -448,7 +448,7 @@ bool find_visual_studio_by_fighting_through_microsoft_craziness(Find_Result *res
             auto version_bytes = (tools_file_size.QuadPart + 1) * 2;  // Warning: This multiplication by 2 presumes there is no variable-length encoding in the wchars (wacky characters in the file could betray this expectation).
             auto version_bytes = (tools_file_size.QuadPart + 1) * 2;  // Warning: This multiplication by 2 presumes there is no variable-length encoding in the wchars (wacky characters in the file could betray this expectation).
             if (version_bytes > 0x7FFFFFFF) continue;   // Avoid overflow.
             if (version_bytes > 0x7FFFFFFF) continue;   // Avoid overflow.
 
 
-            wchar_t *version = (wchar_t *)calloc(1, version_bytes);
+            wchar_t *version = (wchar_t *)calloc(1, (usize)version_bytes);
             defer (free(version));
             defer (free(version));
 
 
             auto read_result = fgetws(version, (int)version_bytes, f);
             auto read_result = fgetws(version, (int)version_bytes, f);

+ 4 - 4
src/ptr_set.cpp

@@ -91,7 +91,7 @@ gb_inline void ptr_set_grow(PtrSet<T> *s) {
 
 
 template <typename T>
 template <typename T>
 void ptr_set_rehash(PtrSet<T> *s, isize new_count) {
 void ptr_set_rehash(PtrSet<T> *s, isize new_count) {
-	PtrSetIndex i, j;
+	isize i, j;
 	PtrSet<T> ns = {};
 	PtrSet<T> ns = {};
 	ptr_set_init(&ns, s->hashes.allocator);
 	ptr_set_init(&ns, s->hashes.allocator);
 	array_resize(&ns.hashes, new_count);
 	array_resize(&ns.hashes, new_count);
@@ -108,9 +108,9 @@ void ptr_set_rehash(PtrSet<T> *s, isize new_count) {
 		fr = ptr_set__find(&ns, e->ptr);
 		fr = ptr_set__find(&ns, e->ptr);
 		j = ptr_set__add_entry(&ns, e->ptr);
 		j = ptr_set__add_entry(&ns, e->ptr);
 		if (fr.entry_prev == PTR_SET_SENTINEL) {
 		if (fr.entry_prev == PTR_SET_SENTINEL) {
-			ns.hashes.data[fr.hash_index] = j;
+			ns.hashes.data[fr.hash_index] = cast(PtrSetIndex)j;
 		} else {
 		} else {
-			ns.entries.data[fr.entry_prev].next = j;
+			ns.entries.data[fr.entry_prev].next = cast(PtrSetIndex)j;
 		}
 		}
 		ns.entries.data[j].next = fr.entry_index;
 		ns.entries.data[j].next = fr.entry_index;
 		if (ptr_set__full(&ns)) {
 		if (ptr_set__full(&ns)) {
@@ -185,7 +185,7 @@ void ptr_set__erase(PtrSet<T> *s, PtrSetFindResult fr) {
 	} else {
 	} else {
 		s->entries.data[fr.entry_prev].next = s->entries.data[fr.entry_index].next;
 		s->entries.data[fr.entry_prev].next = s->entries.data[fr.entry_index].next;
 	}
 	}
-	if (fr.entry_index == s->entries.count-1) {
+	if (cast(isize)fr.entry_index == s->entries.count-1) {
 		array_pop(&s->entries);
 		array_pop(&s->entries);
 		return;
 		return;
 	}
 	}