| author | |
| committer | |
| log | 0f1f56bb69610ea424ac311db72510b474249095 |
| tree | a485f9250d6a3e38af66b58fe93366392fbd6a81 |
| parent | c211b8f91df3ff7545a8cc3e93b58372eeccfe69 |
| parent | d33766e6c7289b79256b2e50d0dc2344729ff710 |
| signature |
fix some nullptr dereferences on arm-linux-musleabhif6 files changed, 16 insertions(+), 7 deletions(-)
src/all_types.hpp+7-1| ... | @@ -1324,6 +1324,7 @@ struct ZigTypeFloat { | ... | @@ -1324,6 +1324,7 @@ struct ZigTypeFloat { |
| 1324 | size_t bit_count; | 1324 | size_t bit_count; |
| 1325 | }; | 1325 | }; |
| 1326 | 1326 | ||
| 1327 | // Needs to have the same memory layout as ZigTypeVector | ||
| 1327 | struct ZigTypeArray { | 1328 | struct ZigTypeArray { |
| 1328 | ZigType *child_type; | 1329 | ZigType *child_type; |
| 1329 | uint64_t len; | 1330 | uint64_t len; |
| ... | @@ -1512,12 +1513,17 @@ struct ZigTypeBoundFn { | ... | @@ -1512,12 +1513,17 @@ struct ZigTypeBoundFn { |
| 1512 | ZigType *fn_type; | 1513 | ZigType *fn_type; |
| 1513 | }; | 1514 | }; |
| 1514 | 1515 | ||
| 1516 | // Needs to have the same memory layout as ZigTypeArray | ||
| 1515 | struct ZigTypeVector { | 1517 | struct ZigTypeVector { |
| 1516 | // The type must be a pointer, integer, bool, or float | 1518 | // The type must be a pointer, integer, bool, or float |
| 1517 | ZigType *elem_type; | 1519 | ZigType *elem_type; |
| 1518 | uint32_t len; | 1520 | uint64_t len; |
| 1521 | size_t padding; | ||
| 1519 | }; | 1522 | }; |
| 1520 | 1523 | ||
| 1524 | // A lot of code is relying on ZigTypeArray and ZigTypeVector having the same layout/size | ||
| 1525 | static_assert(sizeof(ZigTypeVector) == sizeof(ZigTypeArray), "Size of ZigTypeVector and ZigTypeArray do not match!"); | ||
| 1526 | |||
| 1521 | enum ZigTypeId { | 1527 | enum ZigTypeId { |
| 1522 | ZigTypeIdInvalid, | 1528 | ZigTypeIdInvalid, |
| 1523 | ZigTypeIdMetaType, | 1529 | ZigTypeIdMetaType, |
src/analyze.cpp+1| ... | @@ -5156,6 +5156,7 @@ ZigType *get_vector_type(CodeGen *g, uint32_t len, ZigType *elem_type) { | ... | @@ -5156,6 +5156,7 @@ ZigType *get_vector_type(CodeGen *g, uint32_t len, ZigType *elem_type) { |
| 5156 | } | 5156 | } |
| 5157 | entry->data.vector.len = len; | 5157 | entry->data.vector.len = len; |
| 5158 | entry->data.vector.elem_type = elem_type; | 5158 | entry->data.vector.elem_type = elem_type; |
| 5159 | entry->data.vector.padding = 0; | ||
| 5159 | 5160 | ||
| 5160 | buf_resize(&entry->name, 0); | 5161 | buf_resize(&entry->name, 0); |
| 5161 | buf_appendf(&entry->name, "@Vector(%u, %s)", len, buf_ptr(&elem_type->name)); | 5162 | buf_appendf(&entry->name, "@Vector(%u, %s)", len, buf_ptr(&elem_type->name)); |
src/bigint.cpp+1-1| ... | @@ -1430,7 +1430,7 @@ void bigint_shr(BigInt *dest, const BigInt *op1, const BigInt *op2) { | ... | @@ -1430,7 +1430,7 @@ void bigint_shr(BigInt *dest, const BigInt *op1, const BigInt *op2) { |
| 1430 | uint64_t digit = op1_digits[op_digit_index]; | 1430 | uint64_t digit = op1_digits[op_digit_index]; |
| 1431 | size_t dest_digit_index = op_digit_index - digit_shift_count; | 1431 | size_t dest_digit_index = op_digit_index - digit_shift_count; |
| 1432 | digits[dest_digit_index] = carry | (digit >> leftover_shift_count); | 1432 | digits[dest_digit_index] = carry | (digit >> leftover_shift_count); |
| 1433 | carry = digit << (64 - leftover_shift_count); | 1433 | carry = (leftover_shift_count != 0) ? (digit << (64 - leftover_shift_count)) : 0; |
| 1434 | 1434 | ||
| 1435 | if (dest_digit_index == 0) { break; } | 1435 | if (dest_digit_index == 0) { break; } |
| 1436 | op_digit_index -= 1; | 1436 | op_digit_index -= 1; |
src/codegen.cpp+1-1| ... | @@ -714,7 +714,7 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, ZigType *operand_type | ... | @@ -714,7 +714,7 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, ZigType *operand_type |
| 714 | }; | 714 | }; |
| 715 | 715 | ||
| 716 | if (operand_type->id == ZigTypeIdVector) { | 716 | if (operand_type->id == ZigTypeIdVector) { |
| 717 | sprintf(fn_name, "llvm.%s.with.overflow.v%" PRIu32 "i%" PRIu32, signed_str, | 717 | sprintf(fn_name, "llvm.%s.with.overflow.v%" PRIu64 "i%" PRIu32, signed_str, |
| 718 | operand_type->data.vector.len, int_type->data.integral.bit_count); | 718 | operand_type->data.vector.len, int_type->data.integral.bit_count); |
| 719 | 719 | ||
| 720 | LLVMTypeRef return_elem_types[] = { | 720 | LLVMTypeRef return_elem_types[] = { |
src/ir.cpp+5-3| ... | @@ -15953,7 +15953,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i | ... | @@ -15953,7 +15953,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i |
| 15953 | if (op1->value->type->id == ZigTypeIdVector && op2->value->type->id == ZigTypeIdVector) { | 15953 | if (op1->value->type->id == ZigTypeIdVector && op2->value->type->id == ZigTypeIdVector) { |
| 15954 | if (op1->value->type->data.vector.len != op2->value->type->data.vector.len) { | 15954 | if (op1->value->type->data.vector.len != op2->value->type->data.vector.len) { |
| 15955 | ir_add_error(ira, source_instr, | 15955 | ir_add_error(ira, source_instr, |
| 15956 | buf_sprintf("vector length mismatch: %" PRIu32 " and %" PRIu32, | 15956 | buf_sprintf("vector length mismatch: %" PRIu64 " and %" PRIu64, |
| 15957 | op1->value->type->data.vector.len, op2->value->type->data.vector.len)); | 15957 | op1->value->type->data.vector.len, op2->value->type->data.vector.len)); |
| 15958 | return ira->codegen->invalid_inst_gen; | 15958 | return ira->codegen->invalid_inst_gen; |
| 15959 | } | 15959 | } |
| ... | @@ -18982,7 +18982,7 @@ static IrInstGen *ir_analyze_async_call(IrAnalyze *ira, IrInst* source_instr, Zi | ... | @@ -18982,7 +18982,7 @@ static IrInstGen *ir_analyze_async_call(IrAnalyze *ira, IrInst* source_instr, Zi |
| 18982 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { | 18982 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 18983 | return result_loc; | 18983 | return result_loc; |
| 18984 | } | 18984 | } |
| 18985 | result_loc = ir_implicit_cast2(ira, &call_result_loc->source_instruction->base, result_loc, | 18985 | result_loc = ir_implicit_cast2(ira, source_instr, result_loc, |
| 18986 | get_pointer_to_type(ira->codegen, frame_type, false)); | 18986 | get_pointer_to_type(ira->codegen, frame_type, false)); |
| 18987 | if (type_is_invalid(result_loc->value->type)) | 18987 | if (type_is_invalid(result_loc->value->type)) |
| 18988 | return ira->codegen->invalid_inst_gen; | 18988 | return ira->codegen->invalid_inst_gen; |
| ... | @@ -19967,14 +19967,16 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -19967,14 +19967,16 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr, |
| 19967 | return ira->codegen->invalid_inst_gen; | 19967 | return ira->codegen->invalid_inst_gen; |
| 19968 | 19968 | ||
| 19969 | IrInstGen *stack = nullptr; | 19969 | IrInstGen *stack = nullptr; |
| 19970 | IrInst *stack_src = nullptr; | ||
| 19970 | if (stack_is_non_null) { | 19971 | if (stack_is_non_null) { |
| 19971 | stack = ir_analyze_optional_value_payload_value(ira, source_instr, opt_stack, false); | 19972 | stack = ir_analyze_optional_value_payload_value(ira, source_instr, opt_stack, false); |
| 19972 | if (type_is_invalid(stack->value->type)) | 19973 | if (type_is_invalid(stack->value->type)) |
| 19973 | return ira->codegen->invalid_inst_gen; | 19974 | return ira->codegen->invalid_inst_gen; |
| 19975 | stack_src = &stack->base; | ||
| 19974 | } | 19976 | } |
| 19975 | 19977 | ||
| 19976 | return ir_analyze_fn_call(ira, source_instr, fn, fn_type, fn_ref, first_arg_ptr, first_arg_ptr_src, | 19978 | return ir_analyze_fn_call(ira, source_instr, fn, fn_type, fn_ref, first_arg_ptr, first_arg_ptr_src, |
| 19977 | modifier, stack, &stack->base, false, args_ptr, args_len, nullptr, result_loc); | 19979 | modifier, stack, stack_src, false, args_ptr, args_len, nullptr, result_loc); |
| 19978 | } | 19980 | } |
| 19979 | 19981 | ||
| 19980 | static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCallExtra *instruction) { | 19982 | static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCallExtra *instruction) { |
test/compile_errors.zig+1-1| ... | @@ -1188,7 +1188,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -1188,7 +1188,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1188 | \\ suspend; | 1188 | \\ suspend; |
| 1189 | \\} | 1189 | \\} |
| 1190 | , &[_][]const u8{ | 1190 | , &[_][]const u8{ |
| 1191 | "tmp.zig:3:5: error: expected type '*@Frame(bar)', found '*@Frame(foo)'", | 1191 | "tmp.zig:3:13: error: expected type '*@Frame(bar)', found '*@Frame(foo)'", |
| 1192 | }); | 1192 | }); |
| 1193 | 1193 | ||
| 1194 | cases.add("@Frame() of generic function", | 1194 | cases.add("@Frame() of generic function", |