authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-05 11:44:07-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2019-11-05 11:44:07-05:00
log4e9ab0306ac84227bff1188bbf4d65a1ae5255d9
treea4b31fbbe704dc1d19392ce3ea4f2670b5c2e57c
parent1c22cb5e515548b22ccb260f4451edc119151584
parent9170dcb73f7b654cdf8447452240c3bf8d3de838
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #3587 from LemonBoy/fix-things

Bunch'o'fixes

5 files changed, 65 insertions(+), 16 deletions(-)

lib/std/debug.zig+1-1
......@@ -17,7 +17,7 @@ const maxInt = std.math.maxInt;
1717const File = std.fs.File;
1818const windows = std.os.windows;
1919
20const leb = @import("debug/leb128.zig");
20pub const leb = @import("debug/leb128.zig");
2121
2222pub const FailingAllocator = @import("debug/failing_allocator.zig").FailingAllocator;
2323pub 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) {
42384238 return nullptr;
42394239}
42404240
4241static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {
4241static Error define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {
4242 Error err;
42424243 ZigType *fn_type = fn_table_entry->type_entry;
42434244 assert(!fn_type->data.fn.is_generic);
42444245 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) {
42574258 }
42584259
42594260 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 }
42614264
4265 bool is_noalias = param_info->is_noalias;
42624266 if (is_noalias && get_codegen_ptr_type(param_type) == nullptr) {
42634267 add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter"));
42644268 }
......@@ -4273,6 +4277,8 @@ static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {
42734277 fn_table_entry->variable_list.append(var);
42744278 }
42754279 }
4280
4281 return ErrorNone;
42764282}
42774283
42784284bool 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) {
45964602 if (!fn_table_entry->child_scope)
45974603 fn_table_entry->child_scope = &fn_table_entry->fndef_scope->base;
45984604
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 }
46004609
46014610 ZigType *fn_type = fn_table_entry->type_entry;
46024611 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
16681668 instruction->result_loc = result_loc;
16691669
16701670 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);
16721672
16731673 return &instruction->base;
16741674}
......@@ -11297,7 +11297,10 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
1129711297 if (!const_val)
1129811298 return nullptr;
1129911299
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
1130111304 return const_val->data.x_ptr.data.fn.fn_entry;
1130211305}
1130311306
......@@ -16737,9 +16740,8 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC
1673716740 return ir_finish_anal(ira, cast_instruction);
1673816741 } else if (fn_ref->value.type->id == ZigTypeIdFn) {
1673916742 ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref);
16740 if (fn_table_entry == nullptr)
16741 return ira->codegen->invalid_instruction;
16742 return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
16743 ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value.type;
16744 return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_type,
1674316745 fn_ref, nullptr, is_comptime, call_instruction->fn_inline);
1674416746 } else if (fn_ref->value.type->id == ZigTypeIdBoundFn) {
1674516747 assert(fn_ref->value.special == ConstValSpecialStatic);
......@@ -16756,7 +16758,7 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC
1675616758
1675716759 if (fn_ref->value.type->id == ZigTypeIdFn) {
1675816760 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);
1676016762 } else {
1676116763 ir_add_error_node(ira, fn_ref->source_node,
1676216764 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
2179821800 return ira->codegen->invalid_instruction;
2179921801 }
2180021802
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)) {
2180221805 zig_panic("TODO compile-time execution of cmpxchg");
2180321806 }
2180421807
......@@ -22948,12 +22951,20 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2294822951 if (parent_ptr == nullptr)
2294922952 return ira->codegen->invalid_instruction;
2295022953
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;
2295422954
22955 rel_end = child_array_type->data.array.len;
22956 abs_offset = 0;
22955 if (parent_ptr->special == ConstValSpecialUndef) {
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 }
2295722968 } else {
2295822969 array_val = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node);
2295922970 if (array_val == nullptr)
test/compile_errors.zig+22
......@@ -2,6 +2,28 @@ const tests = @import("tests.zig");
22const builtin = @import("builtin");
33
44pub 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
527 cases.add(
628 "using an unknown len ptr type instead of array",
729 \\const resolutions = [*][*]const u8{
test/stage1/behavior/atomics.zig+7
......@@ -100,3 +100,10 @@ test "cmpxchg with ignored result" {
100100
101101 expectEqual(i32(5678), x);
102102}
103
104var a_global_variable = u32(1234);
105
106test "cmpxchg on a global variable" {
107 _ = @cmpxchgWeak(u32, &a_global_variable, 1234, 42, .Acquire, .Monotonic);
108 expectEqual(u32(42), a_global_variable);
109}