| author | |
| committer | |
| log | d0d615d8197eeb196ac500009637296bd00c6583 |
| tree | eb45310d1e02a8be88574f593b12142e78fea4b3 |
| parent | 74c123cd0a9a045aa5266ea10366863ad81310a0 |
| signature | Commit is signed but in an unrecognized format. |
4 files changed, 17 insertions(+), 11 deletions(-)
src/analyze.cpp+4-4| ... | @@ -626,7 +626,7 @@ ZigType *get_optional_type(CodeGen *g, ZigType *child_type) { | ... | @@ -626,7 +626,7 @@ ZigType *get_optional_type(CodeGen *g, ZigType *child_type) { |
| 626 | if (child_type->zero_bits) { | 626 | if (child_type->zero_bits) { |
| 627 | entry->type_ref = LLVMInt1Type(); | 627 | entry->type_ref = LLVMInt1Type(); |
| 628 | entry->di_type = g->builtin_types.entry_bool->di_type; | 628 | entry->di_type = g->builtin_types.entry_bool->di_type; |
| 629 | } else if (type_is_codegen_pointer(child_type) || child_type->id == ZigTypeIdErrorSet) { | 629 | } else if (type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet) { |
| 630 | assert(child_type->di_type); | 630 | assert(child_type->di_type); |
| 631 | // this is an optimization but also is necessary for calling C | 631 | // this is an optimization but also is necessary for calling C |
| 632 | // functions where all pointers are maybe pointers | 632 | // functions where all pointers are maybe pointers |
| ... | @@ -4170,10 +4170,10 @@ ZigType *get_codegen_ptr_type(ZigType *type) { | ... | @@ -4170,10 +4170,10 @@ ZigType *get_codegen_ptr_type(ZigType *type) { |
| 4170 | } | 4170 | } |
| 4171 | 4171 | ||
| 4172 | bool type_is_nonnull_ptr(ZigType *type) { | 4172 | bool type_is_nonnull_ptr(ZigType *type) { |
| 4173 | return type_is_codegen_pointer(type) && !ptr_allows_addr_zero(type); | 4173 | return type_is_non_optional_pointer(type) && !ptr_allows_addr_zero(type); |
| 4174 | } | 4174 | } |
| 4175 | 4175 | ||
| 4176 | bool type_is_codegen_pointer(ZigType *type) { | 4176 | bool type_is_non_optional_pointer(ZigType *type) { |
| 4177 | return get_codegen_ptr_type(type) == type; | 4177 | return get_codegen_ptr_type(type) == type; |
| 4178 | } | 4178 | } |
| 4179 | 4179 | ||
| ... | @@ -4692,7 +4692,7 @@ bool handle_is_ptr(ZigType *type_entry) { | ... | @@ -4692,7 +4692,7 @@ bool handle_is_ptr(ZigType *type_entry) { |
| 4692 | return type_has_bits(type_entry->data.error_union.payload_type); | 4692 | return type_has_bits(type_entry->data.error_union.payload_type); |
| 4693 | case ZigTypeIdOptional: | 4693 | case ZigTypeIdOptional: |
| 4694 | return type_has_bits(type_entry->data.maybe.child_type) && | 4694 | return type_has_bits(type_entry->data.maybe.child_type) && |
| 4695 | !type_is_codegen_pointer(type_entry->data.maybe.child_type) && | 4695 | !type_is_non_optional_pointer(type_entry->data.maybe.child_type) && |
| 4696 | type_entry->data.maybe.child_type->id != ZigTypeIdErrorSet; | 4696 | type_entry->data.maybe.child_type->id != ZigTypeIdErrorSet; |
| 4697 | case ZigTypeIdUnion: | 4697 | case ZigTypeIdUnion: |
| 4698 | assert(type_entry->data.unionation.zero_bits_known); | 4698 | assert(type_entry->data.unionation.zero_bits_known); |
src/analyze.hpp+1-1| ... | @@ -61,7 +61,7 @@ ZigVar *find_variable(CodeGen *g, Scope *orig_context, Buf *name, ScopeFnDef **c | ... | @@ -61,7 +61,7 @@ ZigVar *find_variable(CodeGen *g, Scope *orig_context, Buf *name, ScopeFnDef **c |
| 61 | Tld *find_decl(CodeGen *g, Scope *scope, Buf *name); | 61 | Tld *find_decl(CodeGen *g, Scope *scope, Buf *name); |
| 62 | Tld *find_container_decl(CodeGen *g, ScopeDecls *decls_scope, Buf *name); | 62 | Tld *find_container_decl(CodeGen *g, ScopeDecls *decls_scope, Buf *name); |
| 63 | void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node); | 63 | void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node); |
| 64 | bool type_is_codegen_pointer(ZigType *type); | 64 | bool type_is_non_optional_pointer(ZigType *type); |
| 65 | 65 | ||
| 66 | ZigType *get_src_ptr_type(ZigType *type); | 66 | ZigType *get_src_ptr_type(ZigType *type); |
| 67 | ZigType *get_codegen_ptr_type(ZigType *type); | 67 | ZigType *get_codegen_ptr_type(ZigType *type); |
src/codegen.cpp+6-6| ... | @@ -3959,7 +3959,7 @@ static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueR | ... | @@ -3959,7 +3959,7 @@ static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueR |
| 3959 | if (child_type->zero_bits) { | 3959 | if (child_type->zero_bits) { |
| 3960 | return maybe_handle; | 3960 | return maybe_handle; |
| 3961 | } else { | 3961 | } else { |
| 3962 | bool is_scalar = type_is_codegen_pointer(child_type) || child_type->id == ZigTypeIdErrorSet; | 3962 | bool is_scalar = type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet; |
| 3963 | if (is_scalar) { | 3963 | if (is_scalar) { |
| 3964 | return LLVMBuildICmp(g->builder, LLVMIntNE, maybe_handle, LLVMConstNull(maybe_type->type_ref), ""); | 3964 | return LLVMBuildICmp(g->builder, LLVMIntNE, maybe_handle, LLVMConstNull(maybe_type->type_ref), ""); |
| 3965 | } else { | 3965 | } else { |
| ... | @@ -3999,7 +3999,7 @@ static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutable *exec | ... | @@ -3999,7 +3999,7 @@ static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutable *exec |
| 3999 | if (child_type->zero_bits) { | 3999 | if (child_type->zero_bits) { |
| 4000 | return nullptr; | 4000 | return nullptr; |
| 4001 | } else { | 4001 | } else { |
| 4002 | bool is_scalar = type_is_codegen_pointer(child_type) || child_type->id == ZigTypeIdErrorSet; | 4002 | bool is_scalar = type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet; |
| 4003 | if (is_scalar) { | 4003 | if (is_scalar) { |
| 4004 | return maybe_ptr; | 4004 | return maybe_ptr; |
| 4005 | } else { | 4005 | } else { |
| ... | @@ -4862,7 +4862,7 @@ static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, I | ... | @@ -4862,7 +4862,7 @@ static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, I |
| 4862 | } | 4862 | } |
| 4863 | 4863 | ||
| 4864 | LLVMValueRef payload_val = ir_llvm_value(g, instruction->value); | 4864 | LLVMValueRef payload_val = ir_llvm_value(g, instruction->value); |
| 4865 | if (type_is_codegen_pointer(child_type) || child_type->id == ZigTypeIdErrorSet) { | 4865 | if (type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet) { |
| 4866 | return payload_val; | 4866 | return payload_val; |
| 4867 | } | 4867 | } |
| 4868 | 4868 | ||
| ... | @@ -6099,9 +6099,9 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c | ... | @@ -6099,9 +6099,9 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c |
| 6099 | case ZigTypeIdOptional: | 6099 | case ZigTypeIdOptional: |
| 6100 | { | 6100 | { |
| 6101 | ZigType *child_type = type_entry->data.maybe.child_type; | 6101 | ZigType *child_type = type_entry->data.maybe.child_type; |
| 6102 | if (child_type->zero_bits) { | 6102 | if (!type_has_bits(child_type)) { |
| 6103 | return LLVMConstInt(LLVMInt1Type(), const_val->data.x_optional ? 1 : 0, false); | 6103 | return LLVMConstInt(LLVMInt1Type(), const_val->data.x_optional ? 1 : 0, false); |
| 6104 | } else if (type_is_codegen_pointer(child_type)) { | 6104 | } else if (get_codegen_ptr_type(type_entry) != nullptr) { |
| 6105 | return gen_const_val_ptr(g, const_val, name); | 6105 | return gen_const_val_ptr(g, const_val, name); |
| 6106 | } else if (child_type->id == ZigTypeIdErrorSet) { | 6106 | } else if (child_type->id == ZigTypeIdErrorSet) { |
| 6107 | return gen_const_val_err_set(g, const_val, name); | 6107 | return gen_const_val_err_set(g, const_val, name); |
| ... | @@ -8513,7 +8513,7 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu | ... | @@ -8513,7 +8513,7 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu |
| 8513 | if (child_type->zero_bits) { | 8513 | if (child_type->zero_bits) { |
| 8514 | buf_init_from_str(out_buf, "bool"); | 8514 | buf_init_from_str(out_buf, "bool"); |
| 8515 | return; | 8515 | return; |
| 8516 | } else if (type_is_codegen_pointer(child_type)) { | 8516 | } else if (type_is_non_optional_pointer(child_type)) { |
| 8517 | return get_c_type(g, gen_h, child_type, out_buf); | 8517 | return get_c_type(g, gen_h, child_type, out_buf); |
| 8518 | } else { | 8518 | } else { |
| 8519 | zig_unreachable(); | 8519 | zig_unreachable(); |
test/stage1/behavior/pointers.zig+6| ... | @@ -124,3 +124,9 @@ test "implicit cast error unions with non-optional to optional pointer" { | ... | @@ -124,3 +124,9 @@ test "implicit cast error unions with non-optional to optional pointer" { |
| 124 | S.doTheTest(); | 124 | S.doTheTest(); |
| 125 | comptime S.doTheTest(); | 125 | comptime S.doTheTest(); |
| 126 | } | 126 | } |
| 127 | |||
| 128 | test "initialize const optional C pointer to null" { | ||
| 129 | const a: ?[*c]i32 = null; | ||
| 130 | expect(a == null); | ||
| 131 | comptime expect(a == null); | ||
| 132 | } |