authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-12-19 19:51:57+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-20 15:48:34-05:00
log51cbd968203f348051b8c2bdc005ca5294a79ceb
tree25f84a7e82192ec6b3a6d7fd6798518e6fb49f35
parentf077c3c4ccd03f48f785ee812ab2c88c85792014

Fix sentinel value of opaque pointers in typeInfo

Fixes #3888

2 files changed, 8 insertions(+), 3 deletions(-)

src/ir.cpp+3-3
...@@ -22689,11 +22689,11 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_ent...@@ -22689,11 +22689,11 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_ent
22689 // sentinel: var22689 // sentinel: var
22690 ensure_field_index(result->type, "sentinel", 6);22690 ensure_field_index(result->type, "sentinel", 6);
22691 fields[6]->special = ConstValSpecialStatic;22691 fields[6]->special = ConstValSpecialStatic;
22692 fields[6]->type = get_optional_type(ira->codegen, attrs_type->data.pointer.child_type);22692 if (attrs_type->data.pointer.child_type->id != ZigTypeIdOpaque) {
22693 if (attrs_type->data.pointer.sentinel != nullptr) {22693 fields[6]->type = get_optional_type(ira->codegen, attrs_type->data.pointer.child_type);
22694 fields[6]->data.x_optional = attrs_type->data.pointer.sentinel;22694 fields[6]->data.x_optional = attrs_type->data.pointer.sentinel;
22695 } else {22695 } else {
22696 fields[6]->data.x_optional = nullptr;22696 fields[6]->type = ira->codegen->builtin_types.entry_null;
22697 }22697 }
2269822698
22699 return result;22699 return result;
test/stage1/behavior/type_info.zig+5
...@@ -367,3 +367,8 @@ test "data field is a compile-time value" {...@@ -367,3 +367,8 @@ test "data field is a compile-time value" {
367 };367 };
368 comptime expect(@typeInfo(S).Struct.decls[0].data.Var == isize);368 comptime expect(@typeInfo(S).Struct.decls[0].data.Var == isize);
369}369}
370
371test "sentinel of opaque pointer type" {
372 const c_void_info = @typeInfo(*c_void);
373 expect(c_void_info.Pointer.sentinel == null);
374}