| author | |
| committer | |
| log | 4e9ab0306ac84227bff1188bbf4d65a1ae5255d9 |
| tree | a4b31fbbe704dc1d19392ce3ea4f2670b5c2e57c |
| parent | 1c22cb5e515548b22ccb260f4451edc119151584 |
| parent | 9170dcb73f7b654cdf8447452240c3bf8d3de838 |
| signature |
Bunch'o'fixes5 files changed, 65 insertions(+), 16 deletions(-)
lib/std/debug.zig+1-1| ... | @@ -17,7 +17,7 @@ const maxInt = std.math.maxInt; | ... | @@ -17,7 +17,7 @@ const maxInt = std.math.maxInt; |
| 17 | const File = std.fs.File; | 17 | const File = std.fs.File; |
| 18 | const windows = std.os.windows; | 18 | const windows = std.os.windows; |
| 19 | 19 | ||
| 20 | const leb = @import("debug/leb128.zig"); | 20 | pub const leb = @import("debug/leb128.zig"); |
| 21 | 21 | ||
| 22 | pub const FailingAllocator = @import("debug/failing_allocator.zig").FailingAllocator; | 22 | pub const FailingAllocator = @import("debug/failing_allocator.zig").FailingAllocator; |
| 23 | pub const failing_allocator = &FailingAllocator.init(global_allocator, 0).allocator; | 23 | pub const failing_allocator = &FailingAllocator.init(global_allocator, 0).allocator; |
src/analyze.cpp+12-3| ... | @@ -4238,7 +4238,8 @@ AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index) { | ... | @@ -4238,7 +4238,8 @@ AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index) { |
| 4238 | return nullptr; | 4238 | return nullptr; |
| 4239 | } | 4239 | } |
| 4240 | 4240 | ||
| 4241 | static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) { | 4241 | static Error define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) { |
| 4242 | Error err; | ||
| 4242 | ZigType *fn_type = fn_table_entry->type_entry; | 4243 | ZigType *fn_type = fn_table_entry->type_entry; |
| 4243 | assert(!fn_type->data.fn.is_generic); | 4244 | assert(!fn_type->data.fn.is_generic); |
| 4244 | FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id; | 4245 | FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id; |
| ... | @@ -4257,8 +4258,11 @@ static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) { | ... | @@ -4257,8 +4258,11 @@ static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) { |
| 4257 | } | 4258 | } |
| 4258 | 4259 | ||
| 4259 | ZigType *param_type = param_info->type; | 4260 | ZigType *param_type = param_info->type; |
| 4260 | bool is_noalias = param_info->is_noalias; | 4261 | if ((err = type_resolve(g, param_type, ResolveStatusSizeKnown))) { |
| 4262 | return err; | ||
| 4263 | } | ||
| 4261 | 4264 | ||
| 4265 | bool is_noalias = param_info->is_noalias; | ||
| 4262 | if (is_noalias && get_codegen_ptr_type(param_type) == nullptr) { | 4266 | if (is_noalias && get_codegen_ptr_type(param_type) == nullptr) { |
| 4263 | add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter")); | 4267 | add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter")); |
| 4264 | } | 4268 | } |
| ... | @@ -4273,6 +4277,8 @@ static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) { | ... | @@ -4273,6 +4277,8 @@ static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) { |
| 4273 | fn_table_entry->variable_list.append(var); | 4277 | fn_table_entry->variable_list.append(var); |
| 4274 | } | 4278 | } |
| 4275 | } | 4279 | } |
| 4280 | |||
| 4281 | return ErrorNone; | ||
| 4276 | } | 4282 | } |
| 4277 | 4283 | ||
| 4278 | bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node) { | 4284 | bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node) { |
| ... | @@ -4596,7 +4602,10 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) { | ... | @@ -4596,7 +4602,10 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) { |
| 4596 | if (!fn_table_entry->child_scope) | 4602 | if (!fn_table_entry->child_scope) |
| 4597 | fn_table_entry->child_scope = &fn_table_entry->fndef_scope->base; | 4603 | fn_table_entry->child_scope = &fn_table_entry->fndef_scope->base; |
| 4598 | 4604 | ||
| 4599 | define_local_param_variables(g, fn_table_entry); | 4605 | if (define_local_param_variables(g, fn_table_entry) != ErrorNone) { |
| 4606 | fn_table_entry->anal_state = FnAnalStateInvalid; | ||
| 4607 | return; | ||
| 4608 | } | ||
| 4600 | 4609 | ||
| 4601 | ZigType *fn_type = fn_table_entry->type_entry; | 4610 | ZigType *fn_type = fn_table_entry->type_entry; |
| 4602 | assert(!fn_type->data.fn.is_generic); | 4611 | assert(!fn_type->data.fn.is_generic); |
src/ir.cpp+23-12| ... | @@ -1668,7 +1668,7 @@ static IrInstruction *ir_build_resize_slice(IrAnalyze *ira, IrInstruction *sourc | ... | @@ -1668,7 +1668,7 @@ static IrInstruction *ir_build_resize_slice(IrAnalyze *ira, IrInstruction *sourc |
| 1668 | instruction->result_loc = result_loc; | 1668 | instruction->result_loc = result_loc; |
| 1669 | 1669 | ||
| 1670 | ir_ref_instruction(operand, ira->new_irb.current_basic_block); | 1670 | ir_ref_instruction(operand, ira->new_irb.current_basic_block); |
| 1671 | ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); | 1671 | if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); |
| 1672 | 1672 | ||
| 1673 | return &instruction->base; | 1673 | return &instruction->base; |
| 1674 | } | 1674 | } |
| ... | @@ -11297,7 +11297,10 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) { | ... | @@ -11297,7 +11297,10 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) { |
| 11297 | if (!const_val) | 11297 | if (!const_val) |
| 11298 | return nullptr; | 11298 | return nullptr; |
| 11299 | 11299 | ||
| 11300 | assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction); | 11300 | // May be a ConstPtrSpecialHardCodedAddr |
| 11301 | if (const_val->data.x_ptr.special != ConstPtrSpecialFunction) | ||
| 11302 | return nullptr; | ||
| 11303 | |||
| 11301 | return const_val->data.x_ptr.data.fn.fn_entry; | 11304 | return const_val->data.x_ptr.data.fn.fn_entry; |
| 11302 | } | 11305 | } |
| 11303 | 11306 | ||
| ... | @@ -16737,9 +16740,8 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC | ... | @@ -16737,9 +16740,8 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC |
| 16737 | return ir_finish_anal(ira, cast_instruction); | 16740 | return ir_finish_anal(ira, cast_instruction); |
| 16738 | } else if (fn_ref->value.type->id == ZigTypeIdFn) { | 16741 | } else if (fn_ref->value.type->id == ZigTypeIdFn) { |
| 16739 | ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref); | 16742 | ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref); |
| 16740 | if (fn_table_entry == nullptr) | 16743 | ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value.type; |
| 16741 | return ira->codegen->invalid_instruction; | 16744 | return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_type, |
| 16742 | return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, | ||
| 16743 | fn_ref, nullptr, is_comptime, call_instruction->fn_inline); | 16745 | fn_ref, nullptr, is_comptime, call_instruction->fn_inline); |
| 16744 | } else if (fn_ref->value.type->id == ZigTypeIdBoundFn) { | 16746 | } else if (fn_ref->value.type->id == ZigTypeIdBoundFn) { |
| 16745 | assert(fn_ref->value.special == ConstValSpecialStatic); | 16747 | assert(fn_ref->value.special == ConstValSpecialStatic); |
| ... | @@ -16756,7 +16758,7 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC | ... | @@ -16756,7 +16758,7 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC |
| 16756 | 16758 | ||
| 16757 | if (fn_ref->value.type->id == ZigTypeIdFn) { | 16759 | if (fn_ref->value.type->id == ZigTypeIdFn) { |
| 16758 | return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value.type, | 16760 | return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value.type, |
| 16759 | fn_ref, nullptr, false, FnInlineAuto); | 16761 | fn_ref, nullptr, false, call_instruction->fn_inline); |
| 16760 | } else { | 16762 | } else { |
| 16761 | ir_add_error_node(ira, fn_ref->source_node, | 16763 | ir_add_error_node(ira, fn_ref->source_node, |
| 16762 | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value.type->name))); | 16764 | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value.type->name))); |
| ... | @@ -21798,7 +21800,8 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi | ... | @@ -21798,7 +21800,8 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi |
| 21798 | return ira->codegen->invalid_instruction; | 21800 | return ira->codegen->invalid_instruction; |
| 21799 | } | 21801 | } |
| 21800 | 21802 | ||
| 21801 | if (instr_is_comptime(casted_ptr) && instr_is_comptime(casted_cmp_value) && instr_is_comptime(casted_new_value)) { | 21803 | if (instr_is_comptime(casted_ptr) && casted_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar && |
| 21804 | instr_is_comptime(casted_cmp_value) && instr_is_comptime(casted_new_value)) { | ||
| 21802 | zig_panic("TODO compile-time execution of cmpxchg"); | 21805 | zig_panic("TODO compile-time execution of cmpxchg"); |
| 21803 | } | 21806 | } |
| 21804 | 21807 | ||
| ... | @@ -22948,12 +22951,20 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction | ... | @@ -22948,12 +22951,20 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 22948 | if (parent_ptr == nullptr) | 22951 | if (parent_ptr == nullptr) |
| 22949 | return ira->codegen->invalid_instruction; | 22952 | return ira->codegen->invalid_instruction; |
| 22950 | 22953 | ||
| 22951 | array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.source_node); | ||
| 22952 | if (array_val == nullptr) | ||
| 22953 | return ira->codegen->invalid_instruction; | ||
| 22954 | 22954 | ||
| 22955 | rel_end = child_array_type->data.array.len; | 22955 | if (parent_ptr->special == ConstValSpecialUndef) { |
| 22956 | abs_offset = 0; | 22956 | array_val = nullptr; |
| 22957 | abs_offset = 0; | ||
| 22958 | rel_end = SIZE_MAX; | ||
| 22959 | ptr_is_undef = true; | ||
| 22960 | } else { | ||
| 22961 | array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.source_node); | ||
| 22962 | if (array_val == nullptr) | ||
| 22963 | return ira->codegen->invalid_instruction; | ||
| 22964 | |||
| 22965 | rel_end = child_array_type->data.array.len; | ||
| 22966 | abs_offset = 0; | ||
| 22967 | } | ||
| 22957 | } else { | 22968 | } else { |
| 22958 | array_val = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node); | 22969 | array_val = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node); |
| 22959 | if (array_val == nullptr) | 22970 | if (array_val == nullptr) |
test/compile_errors.zig+22| ... | @@ -2,6 +2,28 @@ const tests = @import("tests.zig"); | ... | @@ -2,6 +2,28 @@ const tests = @import("tests.zig"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | cases.add( | ||
| 6 | "slicing of global undefined pointer", | ||
| 7 | \\var buf: *[1]u8 = undefined; | ||
| 8 | \\export fn entry() void { | ||
| 9 | \\ _ = buf[0..1]; | ||
| 10 | \\} | ||
| 11 | , | ||
| 12 | "tmp.zig:3:12: error: non-zero length slice of undefined pointer", | ||
| 13 | ); | ||
| 14 | |||
| 15 | cases.add( | ||
| 16 | "using invalid types in function call raises an error", | ||
| 17 | \\const MenuEffect = enum {}; | ||
| 18 | \\fn func(effect: MenuEffect) void {} | ||
| 19 | \\export fn entry() void { | ||
| 20 | \\ func(MenuEffect.ThisDoesNotExist); | ||
| 21 | \\} | ||
| 22 | , | ||
| 23 | "tmp.zig:1:20: error: enums must have 1 or more fields", | ||
| 24 | "tmp.zig:4:20: note: referenced here", | ||
| 25 | ); | ||
| 26 | |||
| 5 | cases.add( | 27 | cases.add( |
| 6 | "using an unknown len ptr type instead of array", | 28 | "using an unknown len ptr type instead of array", |
| 7 | \\const resolutions = [*][*]const u8{ | 29 | \\const resolutions = [*][*]const u8{ |
test/stage1/behavior/atomics.zig+7| ... | @@ -100,3 +100,10 @@ test "cmpxchg with ignored result" { | ... | @@ -100,3 +100,10 @@ test "cmpxchg with ignored result" { |
| 100 | 100 | ||
| 101 | expectEqual(i32(5678), x); | 101 | expectEqual(i32(5678), x); |
| 102 | } | 102 | } |
| 103 | |||
| 104 | var a_global_variable = u32(1234); | ||
| 105 | |||
| 106 | test "cmpxchg on a global variable" { | ||
| 107 | _ = @cmpxchgWeak(u32, &a_global_variable, 1234, 42, .Acquire, .Monotonic); | ||
| 108 | expectEqual(u32(42), a_global_variable); | ||
| 109 | } |