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) {
36793679}
36803680
36813681bool type_is_codegen_pointer(TypeTableEntry *type) {
3682 return get_codegen_ptr_type(type) != nullptr;
3682 return get_codegen_ptr_type(type) == type;
36833683}
36843684
36853685uint32_t get_ptr_align(TypeTableEntry *type) {
......@@ -3688,6 +3688,8 @@ uint32_t get_ptr_align(TypeTableEntry *type) {
36883688 return ptr_type->data.pointer.alignment;
36893689 } else if (ptr_type->id == TypeTableEntryIdFn) {
36903690 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;
36913693 } else {
36923694 zig_unreachable();
36933695 }
......@@ -3723,7 +3725,7 @@ static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entr
37233725 TypeTableEntry *param_type = param_info->type;
37243726 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) {
37273729 add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter"));
37283730 }
37293731
src/ir.cpp+8-10
......@@ -16470,12 +16470,12 @@ static TypeTableEntry *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruc
1647016470 if (type_is_invalid(src_type))
1647116471 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) {
1647416474 ir_add_error(ira, ptr, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name)));
1647516475 return ira->codegen->builtin_types.entry_invalid;
1647616476 }
1647716477
16478 if (!type_is_codegen_pointer(dest_type)) {
16478 if (get_codegen_ptr_type(dest_type) == nullptr) {
1647916479 ir_add_error(ira, dest_type_value,
1648016480 buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
1648116481 return ira->codegen->builtin_types.entry_invalid;
......@@ -16662,9 +16662,9 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc
1666216662 ensure_complete_type(ira->codegen, dest_type);
1666316663 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) {
1666616666 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)));
1666816668 return ira->codegen->builtin_types.entry_invalid;
1666916669 }
1667016670
......@@ -16689,9 +16689,9 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc
1668916689 break;
1669016690 }
1669116691
16692 if (type_is_codegen_pointer(dest_type)) {
16692 if (get_codegen_ptr_type(dest_type) != nullptr) {
1669316693 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)));
1669516695 return ira->codegen->builtin_types.entry_invalid;
1669616696 }
1669716697
......@@ -16752,7 +16752,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstr
1675216752 if (type_is_invalid(dest_type))
1675316753 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) {
1675616756 ir_add_error(ira, dest_type_value, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
1675716757 return ira->codegen->builtin_types.entry_invalid;
1675816758 }
......@@ -16858,9 +16858,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr
1685816858
1685916859 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
1686016860
16861 if (!(type_is_codegen_pointer(target->value.type) || (target->value.type->id == TypeTableEntryIdMaybe &&
16862 type_is_codegen_pointer(target->value.type->data.maybe.child_type))))
16863 {
16861 if (get_codegen_ptr_type(target->value.type) == nullptr) {
1686416862 ir_add_error(ira, target,
1686516863 buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value.type->name)));
1686616864 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,
235235 };
236236}
237237
238test "basicHashMapTest" {
238test "basic hash map usage" {
239239 var map = HashMap(i32, i32, hash_i32, eql_i32).init(debug.global_allocator);
240240 defer map.deinit();
241241