From 2f740fa19ff88981d028289162b3eb469b7f5315 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 4 Nov 2019 09:54:13 +0100 Subject: Fix cmpxchg trying to execute at CT Fixes #3582 --- src/ir.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index a53367a324..ce0e204e63 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -21798,7 +21798,8 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi return ira->codegen->invalid_instruction; } - if (instr_is_comptime(casted_ptr) && instr_is_comptime(casted_cmp_value) && instr_is_comptime(casted_new_value)) { + if (instr_is_comptime(casted_ptr) && casted_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar && + instr_is_comptime(casted_cmp_value) && instr_is_comptime(casted_new_value)) { zig_panic("TODO compile-time execution of cmpxchg"); } -- cgit v1.2.3 From 2b4bf1e7ced151482ce741788eadcb39f6d60f72 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 4 Nov 2019 10:38:48 +0100 Subject: Fix crash in #3483 The bytesToSlice is still not evaluated at comptime but at least it doesn't crash anymore. --- src/ir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index ce0e204e63..ea87999454 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -1668,7 +1668,7 @@ static IrInstruction *ir_build_resize_slice(IrAnalyze *ira, IrInstruction *sourc instruction->result_loc = result_loc; ir_ref_instruction(operand, ira->new_irb.current_basic_block); - ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); + if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); return &instruction->base; } -- cgit v1.2.3 From c47211cc60a826837191fbb87b32f0baacb167cb Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 4 Nov 2019 15:09:11 +0100 Subject: Prevent crash when slicing undefined ptr to slice Fixes #3534 --- src/ir.cpp | 18 +++++++++++++----- test/compile_errors.zig | 10 ++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index ea87999454..211af9a758 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -22949,12 +22949,20 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction if (parent_ptr == nullptr) return ira->codegen->invalid_instruction; - array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.source_node); - if (array_val == nullptr) - return ira->codegen->invalid_instruction; - rel_end = child_array_type->data.array.len; - abs_offset = 0; + if (parent_ptr->special == ConstValSpecialUndef) { + array_val = nullptr; + abs_offset = 0; + rel_end = SIZE_MAX; + ptr_is_undef = true; + } else { + array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.source_node); + if (array_val == nullptr) + return ira->codegen->invalid_instruction; + + rel_end = child_array_type->data.array.len; + abs_offset = 0; + } } else { array_val = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node); if (array_val == nullptr) diff --git a/test/compile_errors.zig b/test/compile_errors.zig index a49ad8c117..a9d93dd882 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -2,6 +2,16 @@ const tests = @import("tests.zig"); const builtin = @import("builtin"); pub fn addCases(cases: *tests.CompileErrorContext) void { + cases.add( + "slicing of global undefined pointer", + \\var buf: *[1]u8 = undefined; + \\export fn entry() void { + \\ _ = buf[0..1]; + \\} + , + "tmp.zig:3:12: error: non-zero length slice of undefined pointer", + ); + cases.add( "using invalid types in function call raises an error", \\const MenuEffect = enum {}; -- cgit v1.2.3 From 9170dcb73f7b654cdf8447452240c3bf8d3de838 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 4 Nov 2019 15:32:51 +0100 Subject: Fix #3558 Finding a suitable test case is left as an exercise to the reader. --- src/ir.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index 211af9a758..35ef2b98e2 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -11297,7 +11297,10 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) { if (!const_val) return nullptr; - assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction); + // May be a ConstPtrSpecialHardCodedAddr + if (const_val->data.x_ptr.special != ConstPtrSpecialFunction) + return nullptr; + return const_val->data.x_ptr.data.fn.fn_entry; } @@ -16737,9 +16740,8 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC return ir_finish_anal(ira, cast_instruction); } else if (fn_ref->value.type->id == ZigTypeIdFn) { ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref); - if (fn_table_entry == nullptr) - return ira->codegen->invalid_instruction; - return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, + ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value.type; + return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_type, fn_ref, nullptr, is_comptime, call_instruction->fn_inline); } else if (fn_ref->value.type->id == ZigTypeIdBoundFn) { assert(fn_ref->value.special == ConstValSpecialStatic); @@ -16756,7 +16758,7 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC if (fn_ref->value.type->id == ZigTypeIdFn) { return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value.type, - fn_ref, nullptr, false, FnInlineAuto); + fn_ref, nullptr, false, call_instruction->fn_inline); } else { ir_add_error_node(ira, fn_ref->source_node, buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value.type->name))); -- cgit v1.2.3