diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-09-18 17:51:50 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-09-18 17:51:50 -0400 |
| commit | 345f8db1c49efe3d9ca9859a296f24e728a3b43a (patch) | |
| tree | c0b6d17a4ef6f444365f0af57682bb9a29c5cbd5 /src/analyze.cpp | |
| parent | c1af3605328d21f59ee8ceba3c7350193f0a2429 (diff) | |
| download | zig-345f8db1c49efe3d9ca9859a296f24e728a3b43a.tar.gz zig-345f8db1c49efe3d9ca9859a296f24e728a3b43a.zip | |
fix optional pointer to empty struct incorrectly being non-null
closes #1178
Diffstat (limited to 'src/analyze.cpp')
| -rw-r--r-- | src/analyze.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index 328eda786c..f37418e4f4 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -3971,7 +3971,7 @@ void resolve_container_type(CodeGen *g, ZigType *type_entry) { } } -ZigType *get_codegen_ptr_type(ZigType *type) { +ZigType *get_src_ptr_type(ZigType *type) { if (type->id == ZigTypeIdPointer) return type; if (type->id == ZigTypeIdFn) return type; if (type->id == ZigTypeIdPromise) return type; @@ -3983,12 +3983,19 @@ ZigType *get_codegen_ptr_type(ZigType *type) { return nullptr; } +ZigType *get_codegen_ptr_type(ZigType *type) { + ZigType *ty = get_src_ptr_type(type); + if (ty == nullptr || !type_has_bits(ty)) + return nullptr; + return ty; +} + bool type_is_codegen_pointer(ZigType *type) { return get_codegen_ptr_type(type) == type; } uint32_t get_ptr_align(CodeGen *g, ZigType *type) { - ZigType *ptr_type = get_codegen_ptr_type(type); + ZigType *ptr_type = get_src_ptr_type(type); if (ptr_type->id == ZigTypeIdPointer) { return (ptr_type->data.pointer.explicit_alignment == 0) ? get_abi_alignment(g, ptr_type->data.pointer.child_type) : ptr_type->data.pointer.explicit_alignment; @@ -3996,6 +4003,7 @@ uint32_t get_ptr_align(CodeGen *g, ZigType *type) { // I tried making this use LLVMABIAlignmentOfType but it trips this assertion in LLVM: // "Cannot getTypeInfo() on a type that is unsized!" // when getting the alignment of `?extern fn() void`. + // See http://lists.llvm.org/pipermail/llvm-dev/2018-September/126142.html return (ptr_type->data.fn.fn_type_id.alignment == 0) ? 1 : ptr_type->data.fn.fn_type_id.alignment; } else if (ptr_type->id == ZigTypeIdPromise) { return get_coro_frame_align_bytes(g); @@ -4005,7 +4013,7 @@ uint32_t get_ptr_align(CodeGen *g, ZigType *type) { } bool get_ptr_const(ZigType *type) { - ZigType *ptr_type = get_codegen_ptr_type(type); + ZigType *ptr_type = get_src_ptr_type(type); if (ptr_type->id == ZigTypeIdPointer) { return ptr_type->data.pointer.is_const; } else if (ptr_type->id == ZigTypeIdFn) { |
