From 40dbcd09da27a271c5d1b0990e712bd2b2bfe68d Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 23 Feb 2018 12:49:21 -0500 Subject: [PATCH] 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 --- src/analyze.cpp | 6 ++++-- src/ir.cpp | 18 ++++++++---------- std/hash_map.zig | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/analyze.cpp b/src/analyze.cpp index c00014d8ca..cf5d9e0eab 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -3679,7 +3679,7 @@ TypeTableEntry *get_codegen_ptr_type(TypeTableEntry *type) { } bool type_is_codegen_pointer(TypeTableEntry *type) { - return get_codegen_ptr_type(type) != nullptr; + return get_codegen_ptr_type(type) == type; } uint32_t get_ptr_align(TypeTableEntry *type) { @@ -3688,6 +3688,8 @@ uint32_t get_ptr_align(TypeTableEntry *type) { return ptr_type->data.pointer.alignment; } else if (ptr_type->id == TypeTableEntryIdFn) { return (ptr_type->data.fn.fn_type_id.alignment == 0) ? 1 : ptr_type->data.fn.fn_type_id.alignment; + } else if (ptr_type->id == TypeTableEntryIdPromise) { + return 1; } else { zig_unreachable(); } @@ -3723,7 +3725,7 @@ static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entr TypeTableEntry *param_type = param_info->type; bool is_noalias = param_info->is_noalias; - if (is_noalias && !type_is_codegen_pointer(param_type)) { + if (is_noalias && get_codegen_ptr_type(param_type) == nullptr) { add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter")); } diff --git a/src/ir.cpp b/src/ir.cpp index 183543b0fe..cc57e20c62 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -16470,12 +16470,12 @@ static TypeTableEntry *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruc if (type_is_invalid(src_type)) return ira->codegen->builtin_types.entry_invalid; - if (!type_is_codegen_pointer(src_type)) { + if (get_codegen_ptr_type(src_type) == nullptr) { ir_add_error(ira, ptr, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name))); return ira->codegen->builtin_types.entry_invalid; } - if (!type_is_codegen_pointer(dest_type)) { + if (get_codegen_ptr_type(dest_type) == nullptr) { ir_add_error(ira, dest_type_value, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -16662,9 +16662,9 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc ensure_complete_type(ira->codegen, dest_type); ensure_complete_type(ira->codegen, src_type); - if (type_is_codegen_pointer(src_type)) { + if (get_codegen_ptr_type(src_type) != nullptr) { ir_add_error(ira, value, - buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&src_type->name))); + buf_sprintf("unable to @bitCast from pointer type '%s'", buf_ptr(&src_type->name))); return ira->codegen->builtin_types.entry_invalid; } @@ -16689,9 +16689,9 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc break; } - if (type_is_codegen_pointer(dest_type)) { + if (get_codegen_ptr_type(dest_type) != nullptr) { ir_add_error(ira, dest_type_value, - buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name))); + buf_sprintf("unable to @bitCast to pointer type '%s'", buf_ptr(&dest_type->name))); return ira->codegen->builtin_types.entry_invalid; } @@ -16752,7 +16752,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstr if (type_is_invalid(dest_type)) return ira->codegen->builtin_types.entry_invalid; - if (!type_is_codegen_pointer(dest_type)) { + if (get_codegen_ptr_type(dest_type) == nullptr) { ir_add_error(ira, dest_type_value, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name))); return ira->codegen->builtin_types.entry_invalid; } @@ -16858,9 +16858,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; - if (!(type_is_codegen_pointer(target->value.type) || (target->value.type->id == TypeTableEntryIdMaybe && - type_is_codegen_pointer(target->value.type->data.maybe.child_type)))) - { + if (get_codegen_ptr_type(target->value.type) == nullptr) { ir_add_error(ira, target, buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value.type->name))); return ira->codegen->builtin_types.entry_invalid; diff --git a/std/hash_map.zig b/std/hash_map.zig index 659783bc84..becced64ff 100644 --- a/std/hash_map.zig +++ b/std/hash_map.zig @@ -235,7 +235,7 @@ pub fn HashMap(comptime K: type, comptime V: type, }; } -test "basicHashMapTest" { +test "basic hash map usage" { var map = HashMap(i32, i32, hash_i32, eql_i32).init(debug.global_allocator); defer map.deinit();