From 51cbd968203f348051b8c2bdc005ca5294a79ceb Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Thu, 19 Dec 2019 19:51:57 +0100 Subject: [PATCH] Fix sentinel value of opaque pointers in typeInfo Fixes #3888 --- src/ir.cpp | 6 +++--- test/stage1/behavior/type_info.zig | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ir.cpp b/src/ir.cpp index 0c7160fa80..3000269ad3 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -22689,11 +22689,11 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_ent // sentinel: var ensure_field_index(result->type, "sentinel", 6); fields[6]->special = ConstValSpecialStatic; - fields[6]->type = get_optional_type(ira->codegen, attrs_type->data.pointer.child_type); - if (attrs_type->data.pointer.sentinel != nullptr) { + if (attrs_type->data.pointer.child_type->id != ZigTypeIdOpaque) { + fields[6]->type = get_optional_type(ira->codegen, attrs_type->data.pointer.child_type); fields[6]->data.x_optional = attrs_type->data.pointer.sentinel; } else { - fields[6]->data.x_optional = nullptr; + fields[6]->type = ira->codegen->builtin_types.entry_null; } return result; diff --git a/test/stage1/behavior/type_info.zig b/test/stage1/behavior/type_info.zig index 5a7268443d..a9d4a1c924 100644 --- a/test/stage1/behavior/type_info.zig +++ b/test/stage1/behavior/type_info.zig @@ -367,3 +367,8 @@ test "data field is a compile-time value" { }; comptime expect(@typeInfo(S).Struct.decls[0].data.Var == isize); } + +test "sentinel of opaque pointer type" { + const c_void_info = @typeInfo(*c_void); + expect(c_void_info.Pointer.sentinel == null); +}