authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-04-02 17:12:09-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-04-02 18:31:19-04:00
log4c38a8cce17979a9e8ce15c8ccfe1b7ccdb59832
tree8d1cb172f37e2a2af6b16fce862e71daea5dc394
parent5aee17e888c0db7ed0d220334f3adeff6e323cb2
signature Commit is signed but in an unrecognized format.

more regression fixes. empty test passes again


3 files changed, 62 insertions(+), 43 deletions(-)

src/analyze.cpp+54-39
...@@ -6252,53 +6252,55 @@ static void resolve_llvm_types_slice(CodeGen *g, ZigType *type, ResolveStatus wa...@@ -6252,53 +6252,55 @@ static void resolve_llvm_types_slice(CodeGen *g, ZigType *type, ResolveStatus wa
6252 ZigType *ptr_type = type->data.structure.fields[slice_ptr_index].type_entry;6252 ZigType *ptr_type = type->data.structure.fields[slice_ptr_index].type_entry;
6253 ZigType *child_type = ptr_type->data.pointer.child_type;6253 ZigType *child_type = ptr_type->data.pointer.child_type;
6254 ZigType *usize_type = g->builtin_types.entry_usize;6254 ZigType *usize_type = g->builtin_types.entry_usize;
6255 LLVMTypeRef usize_llvm_type = get_llvm_type(g, usize_type);
6256 ZigLLVMDIType *usize_llvm_di_type = get_llvm_di_type(g, usize_type);
6257 ZigLLVMDIScope *compile_unit_scope = ZigLLVMCompileUnitToScope(g->compile_unit);
6258 ZigLLVMDIFile *di_file = nullptr;
6259 unsigned line = 0;
62606255
6261 if (type->data.structure.resolve_status < ResolveStatusLLVMFwdDecl) {6256 bool done = false;
6262 bool done = false;6257 if (ptr_type->data.pointer.is_const || ptr_type->data.pointer.is_volatile ||
6263 if (ptr_type->data.pointer.is_const || ptr_type->data.pointer.is_volatile ||6258 ptr_type->data.pointer.explicit_alignment != 0 || ptr_type->data.pointer.allow_zero)
6264 ptr_type->data.pointer.explicit_alignment != 0 || ptr_type->data.pointer.allow_zero)6259 {
6260 ZigType *peer_ptr_type = get_pointer_to_type_extra(g, child_type, false, false,
6261 PtrLenUnknown, 0, 0, 0, false);
6262 ZigType *peer_slice_type = get_slice_type(g, peer_ptr_type);
6263
6264 assertNoError(type_resolve(g, peer_slice_type, wanted_resolve_status));
6265 type->llvm_type = peer_slice_type->llvm_type;
6266 type->llvm_di_type = peer_slice_type->llvm_di_type;
6267 type->data.structure.resolve_status = peer_slice_type->data.structure.resolve_status;
6268 done = true;
6269 }
6270
6271 // If the child type is []const T then we need to make sure the type ref
6272 // and debug info is the same as if the child type were []T.
6273 if (is_slice(child_type)) {
6274 ZigType *child_ptr_type = child_type->data.structure.fields[slice_ptr_index].type_entry;
6275 assert(child_ptr_type->id == ZigTypeIdPointer);
6276 if (child_ptr_type->data.pointer.is_const || child_ptr_type->data.pointer.is_volatile ||
6277 child_ptr_type->data.pointer.explicit_alignment != 0 || child_ptr_type->data.pointer.allow_zero)
6265 {6278 {
6266 ZigType *peer_ptr_type = get_pointer_to_type_extra(g, child_type, false, false,6279 ZigType *grand_child_type = child_ptr_type->data.pointer.child_type;
6280 ZigType *bland_child_ptr_type = get_pointer_to_type_extra(g, grand_child_type, false, false,
6281 PtrLenUnknown, 0, 0, 0, false);
6282 ZigType *bland_child_slice = get_slice_type(g, bland_child_ptr_type);
6283 ZigType *peer_ptr_type = get_pointer_to_type_extra(g, bland_child_slice, false, false,
6267 PtrLenUnknown, 0, 0, 0, false);6284 PtrLenUnknown, 0, 0, 0, false);
6268 ZigType *peer_slice_type = get_slice_type(g, peer_ptr_type);6285 ZigType *peer_slice_type = get_slice_type(g, peer_ptr_type);
62696286
6270 type->llvm_type = get_llvm_type(g, peer_slice_type);6287 assertNoError(type_resolve(g, peer_slice_type, wanted_resolve_status));
6271 type->llvm_di_type = get_llvm_di_type(g, peer_slice_type);6288 type->llvm_type = peer_slice_type->llvm_type;
6289 type->llvm_di_type = peer_slice_type->llvm_di_type;
6290 type->data.structure.resolve_status = peer_slice_type->data.structure.resolve_status;
6272 done = true;6291 done = true;
6273 }6292 }
6293 }
62746294
6275 // If the child type is []const T then we need to make sure the type ref6295 if (done) return;
6276 // and debug info is the same as if the child type were []T.
6277 if (is_slice(child_type)) {
6278 ZigType *child_ptr_type = child_type->data.structure.fields[slice_ptr_index].type_entry;
6279 assert(child_ptr_type->id == ZigTypeIdPointer);
6280 if (child_ptr_type->data.pointer.is_const || child_ptr_type->data.pointer.is_volatile ||
6281 child_ptr_type->data.pointer.explicit_alignment != 0 || child_ptr_type->data.pointer.allow_zero)
6282 {
6283 ZigType *grand_child_type = child_ptr_type->data.pointer.child_type;
6284 ZigType *bland_child_ptr_type = get_pointer_to_type_extra(g, grand_child_type, false, false,
6285 PtrLenUnknown, 0, 0, 0, false);
6286 ZigType *bland_child_slice = get_slice_type(g, bland_child_ptr_type);
6287 ZigType *peer_ptr_type = get_pointer_to_type_extra(g, bland_child_slice, false, false,
6288 PtrLenUnknown, 0, 0, 0, false);
6289 ZigType *peer_slice_type = get_slice_type(g, peer_ptr_type);
6290
6291 type->llvm_type = get_llvm_type(g, peer_slice_type);
6292 type->llvm_di_type = get_llvm_di_type(g, peer_slice_type);
6293 done = true;
6294 }
6295 }
62966296
6297 if (done) {6297 LLVMTypeRef usize_llvm_type = get_llvm_type(g, usize_type);
6298 type->data.structure.resolve_status = ResolveStatusLLVMFull;6298 ZigLLVMDIType *usize_llvm_di_type = get_llvm_di_type(g, usize_type);
6299 return;6299 ZigLLVMDIScope *compile_unit_scope = ZigLLVMCompileUnitToScope(g->compile_unit);
6300 }6300 ZigLLVMDIFile *di_file = nullptr;
6301 unsigned line = 0;
63016302
6303 if (type->data.structure.resolve_status < ResolveStatusLLVMFwdDecl) {
6302 type->llvm_type = LLVMStructCreateNamed(LLVMGetGlobalContext(), buf_ptr(&type->name));6304 type->llvm_type = LLVMStructCreateNamed(LLVMGetGlobalContext(), buf_ptr(&type->name));
63036305
6304 type->llvm_di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder,6306 type->llvm_di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder,
...@@ -6551,6 +6553,12 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type) {...@@ -6551,6 +6553,12 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type) {
6551 assert(enum_type->data.enumeration.complete);6553 assert(enum_type->data.enumeration.complete);
6552 if (enum_type->llvm_di_type != nullptr) return;6554 if (enum_type->llvm_di_type != nullptr) return;
65536555
6556 if (!type_has_bits(enum_type)) {
6557 enum_type->llvm_type = g->builtin_types.entry_void->llvm_type;
6558 enum_type->llvm_di_type = g->builtin_types.entry_void->llvm_di_type;
6559 return;
6560 }
6561
6554 uint32_t field_count = enum_type->data.enumeration.src_field_count;6562 uint32_t field_count = enum_type->data.enumeration.src_field_count;
65556563
6556 assert(enum_type->data.enumeration.fields);6564 assert(enum_type->data.enumeration.fields);
...@@ -6569,6 +6577,7 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type) {...@@ -6569,6 +6577,7 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type) {
6569 }6577 }
65706578
6571 ZigType *tag_int_type = enum_type->data.enumeration.tag_int_type;6579 ZigType *tag_int_type = enum_type->data.enumeration.tag_int_type;
6580 enum_type->llvm_type = get_llvm_type(g, tag_int_type);
65726581
6573 // create debug type for tag6582 // create debug type for tag
6574 AstNode *decl_node = enum_type->data.enumeration.decl_node;6583 AstNode *decl_node = enum_type->data.enumeration.decl_node;
...@@ -6583,7 +6592,6 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type) {...@@ -6583,7 +6592,6 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type) {
6583 get_llvm_di_type(g, tag_int_type), "");6592 get_llvm_di_type(g, tag_int_type), "");
65846593
6585 enum_type->llvm_di_type = tag_di_type;6594 enum_type->llvm_di_type = tag_di_type;
6586 enum_type->llvm_type = get_llvm_type(g, tag_int_type);
6587}6595}
65886596
6589static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveStatus wanted_resolve_status) {6597static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveStatus wanted_resolve_status) {
...@@ -6764,6 +6772,7 @@ static void resolve_llvm_types_pointer(CodeGen *g, ZigType *type) {...@@ -6764,6 +6772,7 @@ static void resolve_llvm_types_pointer(CodeGen *g, ZigType *type) {
6764 uint64_t debug_align_in_bits = 8*type->abi_align;6772 uint64_t debug_align_in_bits = 8*type->abi_align;
6765 type->llvm_di_type = ZigLLVMCreateDebugPointerType(g->dbuilder, elem_type->llvm_di_type,6773 type->llvm_di_type = ZigLLVMCreateDebugPointerType(g->dbuilder, elem_type->llvm_di_type,
6766 debug_size_in_bits, debug_align_in_bits, buf_ptr(&type->name));6774 debug_size_in_bits, debug_align_in_bits, buf_ptr(&type->name));
6775 assertNoError(type_resolve(g, elem_type, ResolveStatusLLVMFull));
6767 } else {6776 } else {
6768 ZigType *host_int_type = get_int_type(g, false, type->data.pointer.host_int_bytes * 8);6777 ZigType *host_int_type = get_int_type(g, false, type->data.pointer.host_int_bytes * 8);
6769 LLVMTypeRef host_int_llvm_type = get_llvm_type(g, host_int_type);6778 LLVMTypeRef host_int_llvm_type = get_llvm_type(g, host_int_type);
...@@ -6939,6 +6948,12 @@ static void resolve_llvm_types_error_union(CodeGen *g, ZigType *type) {...@@ -6939,6 +6948,12 @@ static void resolve_llvm_types_error_union(CodeGen *g, ZigType *type) {
6939static void resolve_llvm_types_array(CodeGen *g, ZigType *type) {6948static void resolve_llvm_types_array(CodeGen *g, ZigType *type) {
6940 if (type->llvm_di_type != nullptr) return;6949 if (type->llvm_di_type != nullptr) return;
69416950
6951 if (!type_has_bits(type)) {
6952 type->llvm_type = g->builtin_types.entry_void->llvm_type;
6953 type->llvm_di_type = g->builtin_types.entry_void->llvm_di_type;
6954 return;
6955 }
6956
6942 ZigType *elem_type = type->data.array.child_type;6957 ZigType *elem_type = type->data.array.child_type;
69436958
6944 // TODO https://github.com/ziglang/zig/issues/14246959 // TODO https://github.com/ziglang/zig/issues/1424
...@@ -7014,7 +7029,7 @@ static void resolve_llvm_types_fn(CodeGen *g, ZigType *fn_type) {...@@ -7014,7 +7029,7 @@ static void resolve_llvm_types_fn(CodeGen *g, ZigType *fn_type) {
7014 gen_param_info->src_index = i;7029 gen_param_info->src_index = i;
7015 gen_param_info->gen_index = SIZE_MAX;7030 gen_param_info->gen_index = SIZE_MAX;
70167031
7017 if (!type_has_bits(type_entry))7032 if (is_c_abi || !type_has_bits(type_entry))
7018 continue;7033 continue;
70197034
7020 ZigType *gen_type;7035 ZigType *gen_type;
src/codegen.cpp+7-4
...@@ -3566,7 +3566,9 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI...@@ -3566,7 +3566,9 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
3566 return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 1, "");3566 return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 1, "");
3567 } else if (array_type->id == ZigTypeIdStruct) {3567 } else if (array_type->id == ZigTypeIdStruct) {
3568 assert(array_type->data.structure.is_slice);3568 assert(array_type->data.structure.is_slice);
3569 if (!type_has_bits(instruction->base.value.type)) {3569
3570 ZigType *ptr_type = instruction->base.value.type;
3571 if (!type_has_bits(ptr_type)) {
3570 if (safety_check_on) {3572 if (safety_check_on) {
3571 assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMIntegerTypeKind);3573 assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMIntegerTypeKind);
3572 add_bounds_check(g, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, array_ptr);3574 add_bounds_check(g, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, array_ptr);
...@@ -5695,6 +5697,7 @@ static void ir_render(CodeGen *g, ZigFn *fn_entry) {...@@ -5695,6 +5697,7 @@ static void ir_render(CodeGen *g, ZigFn *fn_entry) {
5695 IrInstruction *instruction = current_block->instruction_list.at(instr_i);5697 IrInstruction *instruction = current_block->instruction_list.at(instr_i);
5696 if (instruction->ref_count == 0 && !ir_has_side_effects(instruction))5698 if (instruction->ref_count == 0 && !ir_has_side_effects(instruction))
5697 continue;5699 continue;
5700
5698 instruction->llvm_value = ir_render_instruction(g, executable, instruction);5701 instruction->llvm_value = ir_render_instruction(g, executable, instruction);
5699 }5702 }
5700 current_block->llvm_exit_block = LLVMGetInsertBlock(g->builder);5703 current_block->llvm_exit_block = LLVMGetInsertBlock(g->builder);
...@@ -6855,9 +6858,9 @@ static void do_code_gen(CodeGen *g) {...@@ -6855,9 +6858,9 @@ static void do_code_gen(CodeGen *g) {
6855 }6858 }
6856 if (var->decl_node) {6859 if (var->decl_node) {
6857 var->di_loc_var = ZigLLVMCreateParameterVariable(g->dbuilder, get_di_scope(g, var->parent_scope),6860 var->di_loc_var = ZigLLVMCreateParameterVariable(g->dbuilder, get_di_scope(g, var->parent_scope),
6858 buf_ptr(&var->name), import->data.structure.root_struct->di_file,6861 buf_ptr(&var->name), import->data.structure.root_struct->di_file,
6859 (unsigned)(var->decl_node->line + 1),6862 (unsigned)(var->decl_node->line + 1),
6860 get_llvm_di_type(g, gen_type), !g->strip_debug_symbols, 0, (unsigned)(gen_info->gen_index));6863 get_llvm_di_type(g, gen_type), !g->strip_debug_symbols, 0, (unsigned)(gen_info->gen_index+1));
6861 }6864 }
68626865
6863 }6866 }
src/zig_llvm.cpp+1
...@@ -548,6 +548,7 @@ ZigLLVMDILocalVariable *ZigLLVMCreateParameterVariable(ZigLLVMDIBuilder *dbuilde...@@ -548,6 +548,7 @@ ZigLLVMDILocalVariable *ZigLLVMCreateParameterVariable(ZigLLVMDIBuilder *dbuilde
548 ZigLLVMDIType *type, bool always_preserve, unsigned flags, unsigned arg_no)548 ZigLLVMDIType *type, bool always_preserve, unsigned flags, unsigned arg_no)
549{549{
550 assert(flags == 0);550 assert(flags == 0);
551 assert(arg_no != 0);
551 DILocalVariable *result = reinterpret_cast<DIBuilder*>(dbuilder)->createParameterVariable(552 DILocalVariable *result = reinterpret_cast<DIBuilder*>(dbuilder)->createParameterVariable(
552 reinterpret_cast<DIScope*>(scope),553 reinterpret_cast<DIScope*>(scope),
553 name,554 name,