| author | |
| committer | |
| log | f6ac2fa70e7e2eb5d3299dc90c581d139b0bea1b |
| tree | a5f5e4c0135f24aafd07c9c7799083c4d8f75140 |
| parent | 25a5fc32fe68f911f7ac34e513e98cacb0ca17b1 |
4 files changed, 22 insertions(+), 23 deletions(-)
src/analyze.cpp+4-6| ... | ... | @@ -330,12 +330,7 @@ TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool |
| 330 | 330 | TypeTableEntry *canon_child_type = get_underlying_type(child_type); |
| 331 | 331 | assert(canon_child_type->id != TypeTableEntryIdInvalid); |
| 332 | 332 | |
| 333 | ||
| 334 | if (type_is_complete(canon_child_type)) { | |
| 335 | entry->zero_bits = !type_has_bits(canon_child_type); | |
| 336 | } else { | |
| 337 | entry->zero_bits = false; | |
| 338 | } | |
| 333 | entry->zero_bits = !type_has_bits(canon_child_type); | |
| 339 | 334 | |
| 340 | 335 | if (!entry->zero_bits) { |
| 341 | 336 | entry->type_ref = LLVMPointerType(child_type->type_ref, 0); |
| ... | ... | @@ -345,6 +340,8 @@ TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool |
| 345 | 340 | assert(child_type->di_type); |
| 346 | 341 | entry->di_type = ZigLLVMCreateDebugPointerType(g->dbuilder, child_type->di_type, |
| 347 | 342 | debug_size_in_bits, debug_align_in_bits, buf_ptr(&entry->name)); |
| 343 | } else { | |
| 344 | entry->di_type = g->builtin_types.entry_void->di_type; | |
| 348 | 345 | } |
| 349 | 346 | |
| 350 | 347 | entry->data.pointer.child_type = child_type; |
| ... | ... | @@ -2895,6 +2892,7 @@ bool fn_eval_eql(Scope *a, Scope *b) { |
| 2895 | 2892 | bool type_has_bits(TypeTableEntry *type_entry) { |
| 2896 | 2893 | assert(type_entry); |
| 2897 | 2894 | assert(type_entry->id != TypeTableEntryIdInvalid); |
| 2895 | assert(type_has_zero_bits_known(type_entry)); | |
| 2898 | 2896 | return !type_entry->zero_bits; |
| 2899 | 2897 | } |
| 2900 | 2898 |
src/ir.cpp+4-1| ... | ... | @@ -4898,7 +4898,9 @@ static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instr |
| 4898 | 4898 | { |
| 4899 | 4899 | if (pointee_type->id == TypeTableEntryIdMetaType) { |
| 4900 | 4900 | TypeTableEntry *type_entry = pointee->data.x_type; |
| 4901 | ConstExprValue *const_val = ir_build_const_from(ira, instruction, depends_on_compile_var || pointee->depends_on_compile_var); | |
| 4901 | ConstExprValue *const_val = ir_build_const_from(ira, instruction, | |
| 4902 | depends_on_compile_var || pointee->depends_on_compile_var); | |
| 4903 | type_ensure_zero_bits_known(ira->codegen, type_entry); | |
| 4902 | 4904 | const_val->data.x_type = get_pointer_to_type(ira->codegen, type_entry, ptr_is_const); |
| 4903 | 4905 | return pointee_type; |
| 4904 | 4906 | } else { |
| ... | ... | @@ -7199,6 +7201,7 @@ static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruc |
| 7199 | 7201 | return ir_analyze_const_ptr(ira, instruction, mem_slot, var->value.type, false, ptr_special, var->src_is_const); |
| 7200 | 7202 | } else { |
| 7201 | 7203 | ir_build_var_ptr_from(&ira->new_irb, instruction, var); |
| 7204 | type_ensure_zero_bits_known(ira->codegen, var->value.type); | |
| 7202 | 7205 | return get_pointer_to_type(ira->codegen, var->value.type, var->src_is_const); |
| 7203 | 7206 | } |
| 7204 | 7207 | } |
test/cases/misc.zig+14| ... | ... | @@ -473,6 +473,20 @@ fn castSliceToU8Slice() { |
| 473 | 473 | assert(bytes[11] == @maxValue(u8)); |
| 474 | 474 | } |
| 475 | 475 | |
| 476 | fn pointerToVoidReturnType() { | |
| 477 | @setFnTest(this); | |
| 478 | ||
| 479 | %%testPointerToVoidReturnType(); | |
| 480 | } | |
| 481 | fn testPointerToVoidReturnType() -> %void { | |
| 482 | const a = testPointerToVoidReturnType2(); | |
| 483 | return *a; | |
| 484 | } | |
| 485 | const test_pointer_to_void_return_type_x = void{}; | |
| 486 | fn testPointerToVoidReturnType2() -> &const void { | |
| 487 | return &test_pointer_to_void_return_type_x; | |
| 488 | } | |
| 489 | ||
| 476 | 490 | // TODO import from std.cstr |
| 477 | 491 | pub fn cstrlen(ptr: &const u8) -> usize { |
| 478 | 492 | var count: usize = 0; |
test/self_hosted.zig-16| ... | ... | @@ -9,19 +9,3 @@ fn getByte(ptr: ?&u8) -> u8 {*??ptr} |
| 9 | 9 | fn getFirstByte(inline T: type, mem: []T) -> u8 { |
| 10 | 10 | getByte((&u8)(&mem[0])) |
| 11 | 11 | } |
| 12 | ||
| 13 | ||
| 14 | // TODO not passing | |
| 15 | fn pointerToVoidReturnType() { | |
| 16 | @setFnTest(this); | |
| 17 | ||
| 18 | %%testPointerToVoidReturnType(); | |
| 19 | } | |
| 20 | fn testPointerToVoidReturnType() -> %void { | |
| 21 | const a = testPointerToVoidReturnType2(); | |
| 22 | return *a; | |
| 23 | } | |
| 24 | const test_pointer_to_void_return_type_x = void{}; | |
| 25 | fn testPointerToVoidReturnType2() -> &const void { | |
| 26 | return &test_pointer_to_void_return_type_x; | |
| 27 | } |