authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-23 12:49:21-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-23 12:49:21-05:00
log40dbcd09da27a271c5d1b0990e712bd2b2bfe68d
treecb4560cf3a096ccaf150aee41c022fceb063540d
parent99985ad6fc0ff4ff09c0284c40023a9c826f8108

fix type_is_codegen_pointer being used incorrectly

The names of these functions should probably change, but at least the semantics are correct now: * type_is_codegen_pointer - the type is either a fn, ptr, or promise * get_codegen_ptr_type - - ?&T and &T returns &T - ?promise and promise returns promise - ?fn()void and fn()void returns fn()void - otherwise returns nullptr

3 files changed, 13 insertions(+), 13 deletions(-)

src/analyze.cpp+4-2
...@@ -3679,7 +3679,7 @@ TypeTableEntry *get_codegen_ptr_type(TypeTableEntry *type) {...@@ -3679,7 +3679,7 @@ TypeTableEntry *get_codegen_ptr_type(TypeTableEntry *type) {
3679}3679}
36803680
3681bool type_is_codegen_pointer(TypeTableEntry *type) {3681bool type_is_codegen_pointer(TypeTableEntry *type) {
3682 return get_codegen_ptr_type(type) != nullptr;3682 return get_codegen_ptr_type(type) == type;
3683}3683}
36843684
3685uint32_t get_ptr_align(TypeTableEntry *type) {3685uint32_t get_ptr_align(TypeTableEntry *type) {
...@@ -3688,6 +3688,8 @@ uint32_t get_ptr_align(TypeTableEntry *type) {...@@ -3688,6 +3688,8 @@ uint32_t get_ptr_align(TypeTableEntry *type) {
3688 return ptr_type->data.pointer.alignment;3688 return ptr_type->data.pointer.alignment;
3689 } else if (ptr_type->id == TypeTableEntryIdFn) {3689 } else if (ptr_type->id == TypeTableEntryIdFn) {
3690 return (ptr_type->data.fn.fn_type_id.alignment == 0) ? 1 : ptr_type->data.fn.fn_type_id.alignment;3690 return (ptr_type->data.fn.fn_type_id.alignment == 0) ? 1 : ptr_type->data.fn.fn_type_id.alignment;
3691 } else if (ptr_type->id == TypeTableEntryIdPromise) {
3692 return 1;
3691 } else {3693 } else {
3692 zig_unreachable();3694 zig_unreachable();
3693 }3695 }
...@@ -3723,7 +3725,7 @@ static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entr...@@ -3723,7 +3725,7 @@ static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entr
3723 TypeTableEntry *param_type = param_info->type;3725 TypeTableEntry *param_type = param_info->type;
3724 bool is_noalias = param_info->is_noalias;3726 bool is_noalias = param_info->is_noalias;
37253727
3726 if (is_noalias && !type_is_codegen_pointer(param_type)) {3728 if (is_noalias && get_codegen_ptr_type(param_type) == nullptr) {
3727 add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter"));3729 add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter"));
3728 }3730 }
37293731
src/ir.cpp+8-10
...@@ -16470,12 +16470,12 @@ static TypeTableEntry *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruc...@@ -16470,12 +16470,12 @@ static TypeTableEntry *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruc
16470 if (type_is_invalid(src_type))16470 if (type_is_invalid(src_type))
16471 return ira->codegen->builtin_types.entry_invalid;16471 return ira->codegen->builtin_types.entry_invalid;
1647216472
16473 if (!type_is_codegen_pointer(src_type)) {16473 if (get_codegen_ptr_type(src_type) == nullptr) {
16474 ir_add_error(ira, ptr, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name)));16474 ir_add_error(ira, ptr, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name)));
16475 return ira->codegen->builtin_types.entry_invalid;16475 return ira->codegen->builtin_types.entry_invalid;
16476 }16476 }
1647716477
16478 if (!type_is_codegen_pointer(dest_type)) {16478 if (get_codegen_ptr_type(dest_type) == nullptr) {
16479 ir_add_error(ira, dest_type_value,16479 ir_add_error(ira, dest_type_value,
16480 buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));16480 buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
16481 return ira->codegen->builtin_types.entry_invalid;16481 return ira->codegen->builtin_types.entry_invalid;
...@@ -16662,9 +16662,9 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc...@@ -16662,9 +16662,9 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc
16662 ensure_complete_type(ira->codegen, dest_type);16662 ensure_complete_type(ira->codegen, dest_type);
16663 ensure_complete_type(ira->codegen, src_type);16663 ensure_complete_type(ira->codegen, src_type);
1666416664
16665 if (type_is_codegen_pointer(src_type)) {16665 if (get_codegen_ptr_type(src_type) != nullptr) {
16666 ir_add_error(ira, value,16666 ir_add_error(ira, value,
16667 buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&src_type->name)));16667 buf_sprintf("unable to @bitCast from pointer type '%s'", buf_ptr(&src_type->name)));
16668 return ira->codegen->builtin_types.entry_invalid;16668 return ira->codegen->builtin_types.entry_invalid;
16669 }16669 }
1667016670
...@@ -16689,9 +16689,9 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc...@@ -16689,9 +16689,9 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc
16689 break;16689 break;
16690 }16690 }
1669116691
16692 if (type_is_codegen_pointer(dest_type)) {16692 if (get_codegen_ptr_type(dest_type) != nullptr) {
16693 ir_add_error(ira, dest_type_value,16693 ir_add_error(ira, dest_type_value,
16694 buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name)));16694 buf_sprintf("unable to @bitCast to pointer type '%s'", buf_ptr(&dest_type->name)));
16695 return ira->codegen->builtin_types.entry_invalid;16695 return ira->codegen->builtin_types.entry_invalid;
16696 }16696 }
1669716697
...@@ -16752,7 +16752,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstr...@@ -16752,7 +16752,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstr
16752 if (type_is_invalid(dest_type))16752 if (type_is_invalid(dest_type))
16753 return ira->codegen->builtin_types.entry_invalid;16753 return ira->codegen->builtin_types.entry_invalid;
1675416754
16755 if (!type_is_codegen_pointer(dest_type)) {16755 if (get_codegen_ptr_type(dest_type) == nullptr) {
16756 ir_add_error(ira, dest_type_value, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));16756 ir_add_error(ira, dest_type_value, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
16757 return ira->codegen->builtin_types.entry_invalid;16757 return ira->codegen->builtin_types.entry_invalid;
16758 }16758 }
...@@ -16858,9 +16858,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr...@@ -16858,9 +16858,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr
1685816858
16859 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;16859 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
1686016860
16861 if (!(type_is_codegen_pointer(target->value.type) || (target->value.type->id == TypeTableEntryIdMaybe &&16861 if (get_codegen_ptr_type(target->value.type) == nullptr) {
16862 type_is_codegen_pointer(target->value.type->data.maybe.child_type))))
16863 {
16864 ir_add_error(ira, target,16862 ir_add_error(ira, target,
16865 buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value.type->name)));16863 buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value.type->name)));
16866 return ira->codegen->builtin_types.entry_invalid;16864 return ira->codegen->builtin_types.entry_invalid;
std/hash_map.zig+1-1
...@@ -235,7 +235,7 @@ pub fn HashMap(comptime K: type, comptime V: type,...@@ -235,7 +235,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
235 };235 };
236}236}
237237
238test "basicHashMapTest" {238test "basic hash map usage" {
239 var map = HashMap(i32, i32, hash_i32, eql_i32).init(debug.global_allocator);239 var map = HashMap(i32, i32, hash_i32, eql_i32).init(debug.global_allocator);
240 defer map.deinit();240 defer map.deinit();
241241