IR: pass pointerToVoidReturnType test

master
Andrew Kelley 2016-12-28 01:31:46 -05:00
parent 25a5fc32fe
commit f6ac2fa70e
4 changed files with 22 additions and 23 deletions

View File

@ -330,12 +330,7 @@ TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool
TypeTableEntry *canon_child_type = get_underlying_type(child_type);
assert(canon_child_type->id != TypeTableEntryIdInvalid);
if (type_is_complete(canon_child_type)) {
entry->zero_bits = !type_has_bits(canon_child_type);
} else {
entry->zero_bits = false;
}
entry->zero_bits = !type_has_bits(canon_child_type);
if (!entry->zero_bits) {
entry->type_ref = LLVMPointerType(child_type->type_ref, 0);
@ -345,6 +340,8 @@ TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool
assert(child_type->di_type);
entry->di_type = ZigLLVMCreateDebugPointerType(g->dbuilder, child_type->di_type,
debug_size_in_bits, debug_align_in_bits, buf_ptr(&entry->name));
} else {
entry->di_type = g->builtin_types.entry_void->di_type;
}
entry->data.pointer.child_type = child_type;
@ -2895,6 +2892,7 @@ bool fn_eval_eql(Scope *a, Scope *b) {
bool type_has_bits(TypeTableEntry *type_entry) {
assert(type_entry);
assert(type_entry->id != TypeTableEntryIdInvalid);
assert(type_has_zero_bits_known(type_entry));
return !type_entry->zero_bits;
}

View File

@ -4898,7 +4898,9 @@ static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instr
{
if (pointee_type->id == TypeTableEntryIdMetaType) {
TypeTableEntry *type_entry = pointee->data.x_type;
ConstExprValue *const_val = ir_build_const_from(ira, instruction, depends_on_compile_var || pointee->depends_on_compile_var);
ConstExprValue *const_val = ir_build_const_from(ira, instruction,
depends_on_compile_var || pointee->depends_on_compile_var);
type_ensure_zero_bits_known(ira->codegen, type_entry);
const_val->data.x_type = get_pointer_to_type(ira->codegen, type_entry, ptr_is_const);
return pointee_type;
} else {
@ -7199,6 +7201,7 @@ static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruc
return ir_analyze_const_ptr(ira, instruction, mem_slot, var->value.type, false, ptr_special, var->src_is_const);
} else {
ir_build_var_ptr_from(&ira->new_irb, instruction, var);
type_ensure_zero_bits_known(ira->codegen, var->value.type);
return get_pointer_to_type(ira->codegen, var->value.type, var->src_is_const);
}
}

View File

@ -473,6 +473,20 @@ fn castSliceToU8Slice() {
assert(bytes[11] == @maxValue(u8));
}
fn pointerToVoidReturnType() {
@setFnTest(this);
%%testPointerToVoidReturnType();
}
fn testPointerToVoidReturnType() -> %void {
const a = testPointerToVoidReturnType2();
return *a;
}
const test_pointer_to_void_return_type_x = void{};
fn testPointerToVoidReturnType2() -> &const void {
return &test_pointer_to_void_return_type_x;
}
// TODO import from std.cstr
pub fn cstrlen(ptr: &const u8) -> usize {
var count: usize = 0;

View File

@ -9,19 +9,3 @@ fn getByte(ptr: ?&u8) -> u8 {*??ptr}
fn getFirstByte(inline T: type, mem: []T) -> u8 {
getByte((&u8)(&mem[0]))
}
// TODO not passing
fn pointerToVoidReturnType() {
@setFnTest(this);
%%testPointerToVoidReturnType();
}
fn testPointerToVoidReturnType() -> %void {
const a = testPointerToVoidReturnType2();
return *a;
}
const test_pointer_to_void_return_type_x = void{};
fn testPointerToVoidReturnType2() -> &const void {
return &test_pointer_to_void_return_type_x;
}