authorgravatar for johnnymarler@gmail.comJonathan Marler <johnnymarler@gmail.com> 2019-08-22 13:56:04-06:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-23 11:14:08-04:00
log9322eee80aadd6d9f80ebc11d29d09898237a14a
treec8848c067244ee16f9cd5525a366d4bb451ae474
parent0e75fef1decdaba918b2abc84977ecadb010ad32

Encapsulate bigint representation, assert on cast data loss


5 files changed, 55 insertions(+), 31 deletions(-)

src/analyze.cpp+4-4
...@@ -1036,7 +1036,7 @@ static bool analyze_const_align(CodeGen *g, Scope *scope, AstNode *node, uint32_...@@ -1036,7 +1036,7 @@ static bool analyze_const_align(CodeGen *g, Scope *scope, AstNode *node, uint32_
1036 if (type_is_invalid(align_result->type))1036 if (type_is_invalid(align_result->type))
1037 return false;1037 return false;
10381038
1039 uint32_t align_bytes = bigint_as_unsigned(&align_result->data.x_bigint);1039 uint32_t align_bytes = bigint_as_u32(&align_result->data.x_bigint);
1040 if (align_bytes == 0) {1040 if (align_bytes == 0) {
1041 add_node_error(g, node, buf_sprintf("alignment must be >= 1"));1041 add_node_error(g, node, buf_sprintf("alignment must be >= 1"));
1042 return false;1042 return false;
...@@ -1068,7 +1068,7 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **...@@ -1068,7 +1068,7 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **
1068 return true;1068 return true;
1069 }1069 }
1070 expand_undef_array(g, array_val);1070 expand_undef_array(g, array_val);
1071 size_t len = bigint_as_unsigned(&len_field->data.x_bigint);1071 size_t len = bigint_as_usize(&len_field->data.x_bigint);
1072 Buf *result = buf_alloc();1072 Buf *result = buf_alloc();
1073 buf_resize(result, len);1073 buf_resize(result, len);
1074 for (size_t i = 0; i < len; i += 1) {1074 for (size_t i = 0; i < len; i += 1) {
...@@ -1078,7 +1078,7 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **...@@ -1078,7 +1078,7 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **
1078 add_node_error(g, node, buf_sprintf("use of undefined value"));1078 add_node_error(g, node, buf_sprintf("use of undefined value"));
1079 return false;1079 return false;
1080 }1080 }
1081 uint64_t big_c = bigint_as_unsigned(&char_val->data.x_bigint);1081 uint64_t big_c = bigint_as_u64(&char_val->data.x_bigint);
1082 assert(big_c <= UINT8_MAX);1082 assert(big_c <= UINT8_MAX);
1083 uint8_t c = (uint8_t)big_c;1083 uint8_t c = (uint8_t)big_c;
1084 buf_ptr(result)[i] = c;1084 buf_ptr(result)[i] = c;
...@@ -5976,7 +5976,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {...@@ -5976,7 +5976,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
5976 {5976 {
5977 if (is_slice(type_entry)) {5977 if (is_slice(type_entry)) {
5978 ConstExprValue *len_val = &const_val->data.x_struct.fields[slice_len_index];5978 ConstExprValue *len_val = &const_val->data.x_struct.fields[slice_len_index];
5979 size_t len = bigint_as_unsigned(&len_val->data.x_bigint);5979 size_t len = bigint_as_usize(&len_val->data.x_bigint);
59805980
5981 ConstExprValue *ptr_val = &const_val->data.x_struct.fields[slice_ptr_index];5981 ConstExprValue *ptr_val = &const_val->data.x_struct.fields[slice_ptr_index];
5982 if (ptr_val->special == ConstValSpecialUndef) {5982 if (ptr_val->special == ConstValSpecialUndef) {
src/bigint.cpp+22-1
...@@ -15,6 +15,8 @@...@@ -15,6 +15,8 @@
15#include <limits>15#include <limits>
16#include <algorithm>16#include <algorithm>
1717
18static uint64_t bigint_as_unsigned(const BigInt *bigint);
19
18static void bigint_normalize(BigInt *dest) {20static void bigint_normalize(BigInt *dest) {
19 const uint64_t *digits = bigint_ptr(dest);21 const uint64_t *digits = bigint_ptr(dest);
2022
...@@ -1660,7 +1662,7 @@ size_t bigint_clz(const BigInt *bi, size_t bit_count) {...@@ -1660,7 +1662,7 @@ size_t bigint_clz(const BigInt *bi, size_t bit_count) {
1660 return count;1662 return count;
1661}1663}
16621664
1663uint64_t bigint_as_unsigned(const BigInt *bigint) {1665static uint64_t bigint_as_unsigned(const BigInt *bigint) {
1664 assert(!bigint->is_negative);1666 assert(!bigint->is_negative);
1665 if (bigint->digit_count == 0) {1667 if (bigint->digit_count == 0) {
1666 return 0;1668 return 0;
...@@ -1671,6 +1673,25 @@ uint64_t bigint_as_unsigned(const BigInt *bigint) {...@@ -1671,6 +1673,25 @@ uint64_t bigint_as_unsigned(const BigInt *bigint) {
1671 }1673 }
1672}1674}
16731675
1676uint64_t bigint_as_u64(const BigInt *bigint)
1677{
1678 return bigint_as_unsigned(bigint);
1679}
1680
1681uint32_t bigint_as_u32(const BigInt *bigint) {
1682 uint64_t value64 = bigint_as_unsigned(bigint);
1683 uint32_t value32 = (uint32_t)value64;
1684 assert (value64 == value32);
1685 return value32;
1686}
1687
1688size_t bigint_as_usize(const BigInt *bigint) {
1689 uint64_t value64 = bigint_as_unsigned(bigint);
1690 size_t valueUsize = (size_t)value64;
1691 assert (value64 == valueUsize);
1692 return valueUsize;
1693}
1694
1674int64_t bigint_as_signed(const BigInt *bigint) {1695int64_t bigint_as_signed(const BigInt *bigint) {
1675 if (bigint->digit_count == 0) {1696 if (bigint->digit_count == 0) {
1676 return 0;1697 return 0;
src/bigint.hpp+4-1
...@@ -36,7 +36,10 @@ void bigint_init_bigfloat(BigInt *dest, const BigFloat *op);...@@ -36,7 +36,10 @@ void bigint_init_bigfloat(BigInt *dest, const BigFloat *op);
36void bigint_init_data(BigInt *dest, const uint64_t *digits, size_t digit_count, bool is_negative);36void bigint_init_data(BigInt *dest, const uint64_t *digits, size_t digit_count, bool is_negative);
3737
38// panics if number won't fit38// panics if number won't fit
39uint64_t bigint_as_unsigned(const BigInt *bigint);39uint64_t bigint_as_u64(const BigInt *bigint);
40uint32_t bigint_as_u32(const BigInt *bigint);
41size_t bigint_as_usize(const BigInt *bigint);
42
40int64_t bigint_as_signed(const BigInt *bigint);43int64_t bigint_as_signed(const BigInt *bigint);
4144
42static inline const uint64_t *bigint_ptr(const BigInt *bigint) {45static inline const uint64_t *bigint_ptr(const BigInt *bigint) {
src/codegen.cpp+1-1
...@@ -2872,7 +2872,7 @@ static void add_error_range_check(CodeGen *g, ZigType *err_set_type, ZigType *in...@@ -2872,7 +2872,7 @@ static void add_error_range_check(CodeGen *g, ZigType *err_set_type, ZigType *in
2872 eval_min_max_value_int(g, int_type, &biggest_possible_err_val, true);2872 eval_min_max_value_int(g, int_type, &biggest_possible_err_val, true);
28732873
2874 if (bigint_fits_in_bits(&biggest_possible_err_val, 64, false) &&2874 if (bigint_fits_in_bits(&biggest_possible_err_val, 64, false) &&
2875 bigint_as_unsigned(&biggest_possible_err_val) < g->errors_by_index.length)2875 bigint_as_usize(&biggest_possible_err_val) < g->errors_by_index.length)
2876 {2876 {
2877 ok_bit = neq_zero_bit;2877 ok_bit = neq_zero_bit;
2878 } else {2878 } else {
src/ir.cpp+24-24
...@@ -5766,7 +5766,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode...@@ -5766,7 +5766,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
5766 buf_sprintf("value %s too large for u32 bit offset", buf_ptr(val_buf)));5766 buf_sprintf("value %s too large for u32 bit offset", buf_ptr(val_buf)));
5767 return irb->codegen->invalid_instruction;5767 return irb->codegen->invalid_instruction;
5768 }5768 }
5769 bit_offset_start = bigint_as_unsigned(node->data.pointer_type.bit_offset_start);5769 bit_offset_start = bigint_as_u32(node->data.pointer_type.bit_offset_start);
5770 }5770 }
57715771
5772 uint32_t host_int_bytes = 0;5772 uint32_t host_int_bytes = 0;
...@@ -5778,7 +5778,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode...@@ -5778,7 +5778,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
5778 buf_sprintf("value %s too large for u32 byte count", buf_ptr(val_buf)));5778 buf_sprintf("value %s too large for u32 byte count", buf_ptr(val_buf)));
5779 return irb->codegen->invalid_instruction;5779 return irb->codegen->invalid_instruction;
5780 }5780 }
5781 host_int_bytes = bigint_as_unsigned(node->data.pointer_type.host_int_bytes);5781 host_int_bytes = bigint_as_u32(node->data.pointer_type.host_int_bytes);
5782 }5782 }
57835783
5784 if (host_int_bytes != 0 && bit_offset_start >= host_int_bytes * 8) {5784 if (host_int_bytes != 0 && bit_offset_start >= host_int_bytes * 8) {
...@@ -11550,7 +11550,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc...@@ -11550,7 +11550,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
11550 return ira->codegen->invalid_instruction;11550 return ira->codegen->invalid_instruction;
11551 }11551 }
1155211552
11553 size_t index = bigint_as_unsigned(&val->data.x_bigint);11553 size_t index = bigint_as_usize(&val->data.x_bigint);
11554 result->value.data.x_err_set = ira->codegen->errors_by_index.at(index);11554 result->value.data.x_err_set = ira->codegen->errors_by_index.at(index);
11555 return result;11555 return result;
11556 } else {11556 } else {
...@@ -12520,7 +12520,7 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, uint32_t *out...@@ -12520,7 +12520,7 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, uint32_t *out
12520 if (!const_val)12520 if (!const_val)
12521 return false;12521 return false;
1252212522
12523 uint32_t align_bytes = bigint_as_unsigned(&const_val->data.x_bigint);12523 uint32_t align_bytes = bigint_as_u32(&const_val->data.x_bigint);
12524 if (align_bytes == 0) {12524 if (align_bytes == 0) {
12525 ir_add_error(ira, value, buf_sprintf("alignment must be >= 1"));12525 ir_add_error(ira, value, buf_sprintf("alignment must be >= 1"));
12526 return false;12526 return false;
...@@ -12547,7 +12547,7 @@ static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *i...@@ -12547,7 +12547,7 @@ static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *i
12547 if (!const_val)12547 if (!const_val)
12548 return false;12548 return false;
1254912549
12550 *out = bigint_as_unsigned(&const_val->data.x_bigint);12550 *out = bigint_as_u64(&const_val->data.x_bigint);
12551 return true;12551 return true;
12552}12552}
1255312553
...@@ -12595,7 +12595,7 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic...@@ -12595,7 +12595,7 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic
12595 if (!const_val)12595 if (!const_val)
12596 return false;12596 return false;
1259712597
12598 *out = (AtomicOrder)bigint_as_unsigned(&const_val->data.x_enum_tag);12598 *out = (AtomicOrder)bigint_as_u32(&const_val->data.x_enum_tag);
12599 return true;12599 return true;
12600}12600}
1260112601
...@@ -12615,7 +12615,7 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi...@@ -12615,7 +12615,7 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi
12615 if (!const_val)12615 if (!const_val)
12616 return false;12616 return false;
1261712617
12618 *out = (AtomicRmwOp)bigint_as_unsigned(&const_val->data.x_enum_tag);12618 *out = (AtomicRmwOp)bigint_as_u32(&const_val->data.x_enum_tag);
12619 return true;12619 return true;
12620}12620}
1262112621
...@@ -12635,7 +12635,7 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob...@@ -12635,7 +12635,7 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob
12635 if (!const_val)12635 if (!const_val)
12636 return false;12636 return false;
1263712637
12638 *out = (GlobalLinkageId)bigint_as_unsigned(&const_val->data.x_enum_tag);12638 *out = (GlobalLinkageId)bigint_as_u32(&const_val->data.x_enum_tag);
12639 return true;12639 return true;
12640}12640}
1264112641
...@@ -12655,7 +12655,7 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod...@@ -12655,7 +12655,7 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod
12655 if (!const_val)12655 if (!const_val)
12656 return false;12656 return false;
1265712657
12658 *out = (FloatMode)bigint_as_unsigned(&const_val->data.x_enum_tag);12658 *out = (FloatMode)bigint_as_u32(&const_val->data.x_enum_tag);
12659 return true;12659 return true;
12660}12660}
1266112661
...@@ -12684,7 +12684,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {...@@ -12684,7 +12684,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
12684 return array_val->data.x_array.data.s_buf;12684 return array_val->data.x_array.data.s_buf;
12685 }12685 }
12686 expand_undef_array(ira->codegen, array_val);12686 expand_undef_array(ira->codegen, array_val);
12687 size_t len = bigint_as_unsigned(&len_field->data.x_bigint);12687 size_t len = bigint_as_usize(&len_field->data.x_bigint);
12688 Buf *result = buf_alloc();12688 Buf *result = buf_alloc();
12689 buf_resize(result, len);12689 buf_resize(result, len);
12690 for (size_t i = 0; i < len; i += 1) {12690 for (size_t i = 0; i < len; i += 1) {
...@@ -12694,7 +12694,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {...@@ -12694,7 +12694,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
12694 ir_add_error(ira, casted_value, buf_sprintf("use of undefined value"));12694 ir_add_error(ira, casted_value, buf_sprintf("use of undefined value"));
12695 return nullptr;12695 return nullptr;
12696 }12696 }
12697 uint64_t big_c = bigint_as_unsigned(&char_val->data.x_bigint);12697 uint64_t big_c = bigint_as_u64(&char_val->data.x_bigint);
12698 assert(big_c <= UINT8_MAX);12698 assert(big_c <= UINT8_MAX);
12699 uint8_t c = (uint8_t)big_c;12699 uint8_t c = (uint8_t)big_c;
12700 buf_ptr(result)[i] = c;12700 buf_ptr(result)[i] = c;
...@@ -13829,7 +13829,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -13829,7 +13829,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
13829 op1_array_val = ptr_val->data.x_ptr.data.base_array.array_val;13829 op1_array_val = ptr_val->data.x_ptr.data.base_array.array_val;
13830 op1_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;13830 op1_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;
13831 ConstExprValue *len_val = &op1_val->data.x_struct.fields[slice_len_index];13831 ConstExprValue *len_val = &op1_val->data.x_struct.fields[slice_len_index];
13832 op1_array_end = op1_array_index + bigint_as_unsigned(&len_val->data.x_bigint);13832 op1_array_end = op1_array_index + bigint_as_usize(&len_val->data.x_bigint);
13833 } else {13833 } else {
13834 ir_add_error(ira, op1,13834 ir_add_error(ira, op1,
13835 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op1->value.type->name)));13835 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op1->value.type->name)));
...@@ -13862,7 +13862,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -13862,7 +13862,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
13862 op2_array_val = ptr_val->data.x_ptr.data.base_array.array_val;13862 op2_array_val = ptr_val->data.x_ptr.data.base_array.array_val;
13863 op2_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;13863 op2_array_index = ptr_val->data.x_ptr.data.base_array.elem_index;
13864 ConstExprValue *len_val = &op2_val->data.x_struct.fields[slice_len_index];13864 ConstExprValue *len_val = &op2_val->data.x_struct.fields[slice_len_index];
13865 op2_array_end = op2_array_index + bigint_as_unsigned(&len_val->data.x_bigint);13865 op2_array_end = op2_array_index + bigint_as_usize(&len_val->data.x_bigint);
13866 } else {13866 } else {
13867 ir_add_error(ira, op2,13867 ir_add_error(ira, op2,
13868 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value.type->name)));13868 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value.type->name)));
...@@ -16734,7 +16734,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -16734,7 +16734,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
16734 uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type);16734 uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type);
16735 uint64_t ptr_align = get_ptr_align(ira->codegen, return_type);16735 uint64_t ptr_align = get_ptr_align(ira->codegen, return_type);
16736 if (instr_is_comptime(casted_elem_index)) {16736 if (instr_is_comptime(casted_elem_index)) {
16737 uint64_t index = bigint_as_unsigned(&casted_elem_index->value.data.x_bigint);16737 uint64_t index = bigint_as_u64(&casted_elem_index->value.data.x_bigint);
16738 if (array_type->id == ZigTypeIdArray) {16738 if (array_type->id == ZigTypeIdArray) {
16739 uint64_t array_len = array_type->data.array.len;16739 uint64_t array_len = array_type->data.array.len;
16740 if (index >= array_len) {16740 if (index >= array_len) {
...@@ -16896,7 +16896,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -16896,7 +16896,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
16896 ConstExprValue *len_field = &array_ptr_val->data.x_struct.fields[slice_len_index];16896 ConstExprValue *len_field = &array_ptr_val->data.x_struct.fields[slice_len_index];
16897 IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type);16897 IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type);
16898 ConstExprValue *out_val = &result->value;16898 ConstExprValue *out_val = &result->value;
16899 uint64_t slice_len = bigint_as_unsigned(&len_field->data.x_bigint);16899 uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint);
16900 if (index >= slice_len) {16900 if (index >= slice_len) {
16901 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,16901 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
16902 buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64,16902 buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64,
...@@ -21181,7 +21181,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru...@@ -21181,7 +21181,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2118121181
21182 ConstExprValue *len_val = &val->data.x_struct.fields[slice_len_index];21182 ConstExprValue *len_val = &val->data.x_struct.fields[slice_len_index];
21183 if (value_is_comptime(len_val)) {21183 if (value_is_comptime(len_val)) {
21184 known_len = bigint_as_unsigned(&len_val->data.x_bigint);21184 known_len = bigint_as_u64(&len_val->data.x_bigint);
21185 have_known_len = true;21185 have_known_len = true;
21186 }21186 }
21187 }21187 }
...@@ -21527,7 +21527,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio...@@ -21527,7 +21527,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
21527 zig_panic("TODO memset on null ptr");21527 zig_panic("TODO memset on null ptr");
21528 }21528 }
2152921529
21530 size_t count = bigint_as_unsigned(&casted_count->value.data.x_bigint);21530 size_t count = bigint_as_usize(&casted_count->value.data.x_bigint);
21531 size_t end = start + count;21531 size_t end = start + count;
21532 if (end > bound_end) {21532 if (end > bound_end) {
21533 ir_add_error(ira, count_value, buf_sprintf("out of bounds pointer access"));21533 ir_add_error(ira, count_value, buf_sprintf("out of bounds pointer access"));
...@@ -21612,7 +21612,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -21612,7 +21612,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
21612 casted_count->value.special == ConstValSpecialStatic &&21612 casted_count->value.special == ConstValSpecialStatic &&
21613 casted_dest_ptr->value.data.x_ptr.special != ConstPtrSpecialHardCodedAddr)21613 casted_dest_ptr->value.data.x_ptr.special != ConstPtrSpecialHardCodedAddr)
21614 {21614 {
21615 size_t count = bigint_as_unsigned(&casted_count->value.data.x_bigint);21615 size_t count = bigint_as_usize(&casted_count->value.data.x_bigint);
2161621616
21617 ConstExprValue *dest_ptr_val = &casted_dest_ptr->value;21617 ConstExprValue *dest_ptr_val = &casted_dest_ptr->value;
21618 ConstExprValue *dest_elements;21618 ConstExprValue *dest_elements;
...@@ -21897,7 +21897,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -21897,7 +21897,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
21897 case ConstPtrSpecialBaseArray:21897 case ConstPtrSpecialBaseArray:
21898 array_val = parent_ptr->data.x_ptr.data.base_array.array_val;21898 array_val = parent_ptr->data.x_ptr.data.base_array.array_val;
21899 abs_offset = parent_ptr->data.x_ptr.data.base_array.elem_index;21899 abs_offset = parent_ptr->data.x_ptr.data.base_array.elem_index;
21900 rel_end = bigint_as_unsigned(&len_val->data.x_bigint);21900 rel_end = bigint_as_usize(&len_val->data.x_bigint);
21901 break;21901 break;
21902 case ConstPtrSpecialBaseStruct:21902 case ConstPtrSpecialBaseStruct:
21903 zig_panic("TODO slice const inner struct");21903 zig_panic("TODO slice const inner struct");
...@@ -21910,7 +21910,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -21910,7 +21910,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
21910 case ConstPtrSpecialHardCodedAddr:21910 case ConstPtrSpecialHardCodedAddr:
21911 array_val = nullptr;21911 array_val = nullptr;
21912 abs_offset = 0;21912 abs_offset = 0;
21913 rel_end = bigint_as_unsigned(&len_val->data.x_bigint);21913 rel_end = bigint_as_usize(&len_val->data.x_bigint);
21914 break;21914 break;
21915 case ConstPtrSpecialFunction:21915 case ConstPtrSpecialFunction:
21916 zig_panic("TODO slice of slice cast from function");21916 zig_panic("TODO slice of slice cast from function");
...@@ -21921,7 +21921,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -21921,7 +21921,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
21921 zig_unreachable();21921 zig_unreachable();
21922 }21922 }
2192321923
21924 uint64_t start_scalar = bigint_as_unsigned(&casted_start->value.data.x_bigint);21924 uint64_t start_scalar = bigint_as_u64(&casted_start->value.data.x_bigint);
21925 if (!ptr_is_undef && start_scalar > rel_end) {21925 if (!ptr_is_undef && start_scalar > rel_end) {
21926 ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds slice"));21926 ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds slice"));
21927 return ira->codegen->invalid_instruction;21927 return ira->codegen->invalid_instruction;
...@@ -21929,7 +21929,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -21929,7 +21929,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2192921929
21930 uint64_t end_scalar;21930 uint64_t end_scalar;
21931 if (end) {21931 if (end) {
21932 end_scalar = bigint_as_unsigned(&end->value.data.x_bigint);21932 end_scalar = bigint_as_u64(&end->value.data.x_bigint);
21933 } else {21933 } else {
21934 end_scalar = rel_end;21934 end_scalar = rel_end;
21935 }21935 }
...@@ -23500,7 +23500,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou...@@ -23500,7 +23500,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
23500 BigInt bn;23500 BigInt bn;
23501 bigint_read_twos_complement(&bn, buf, codegen->builtin_types.entry_usize->data.integral.bit_count,23501 bigint_read_twos_complement(&bn, buf, codegen->builtin_types.entry_usize->data.integral.bit_count,
23502 codegen->is_big_endian, false);23502 codegen->is_big_endian, false);
23503 val->data.x_ptr.data.hard_coded_addr.addr = bigint_as_unsigned(&bn);23503 val->data.x_ptr.data.hard_coded_addr.addr = bigint_as_usize(&bn);
23504 return ErrorNone;23504 return ErrorNone;
23505 }23505 }
23506 case ZigTypeIdArray:23506 case ZigTypeIdArray:
...@@ -23693,7 +23693,7 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc...@@ -23693,7 +23693,7 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc
23693 if (!val)23693 if (!val)
23694 return ira->codegen->invalid_instruction;23694 return ira->codegen->invalid_instruction;
2369523695
23696 uint64_t addr = bigint_as_unsigned(&val->data.x_bigint);23696 uint64_t addr = bigint_as_u64(&val->data.x_bigint);
23697 if (!ptr_allows_addr_zero(ptr_type) && addr == 0) {23697 if (!ptr_allows_addr_zero(ptr_type) && addr == 0) {
23698 ir_add_error(ira, source_instr,23698 ir_add_error(ira, source_instr,
23699 buf_sprintf("pointer type '%s' does not allow address zero", buf_ptr(&ptr_type->name)));23699 buf_sprintf("pointer type '%s' does not allow address zero", buf_ptr(&ptr_type->name)));