Skip to content

Commit 40dbcd0

Browse files
committed
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
1 parent 99985ad commit 40dbcd0

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/analyze.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3679,7 +3679,7 @@ TypeTableEntry *get_codegen_ptr_type(TypeTableEntry *type) {
36793679
}
36803680

36813681
bool type_is_codegen_pointer(TypeTableEntry *type) {
3682-
return get_codegen_ptr_type(type) != nullptr;
3682+
return get_codegen_ptr_type(type) == type;
36833683
}
36843684

36853685
uint32_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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
235235
};
236236
}
237237

238-
test "basicHashMapTest" {
238+
test "basic hash map usage" {
239239
var map = HashMap(i32, i32, hash_i32, eql_i32).init(debug.global_allocator);
240240
defer map.deinit();
241241

0 commit comments

Comments
 (0)