authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-25 21:28:16-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-25 21:28:16-04:00
log720302a6407e954ffccf65f38ad40b47868627ce
tree959b2b287fad50c77b5a5bbee121d2dd1fad5796
parenta7f31581850fe2811bc5114459a8d193dd48b42a
signaturelock-open Commit is signed but in an unrecognized format.

fix resolution detection of pointer types


2 files changed, 30 insertions(+), 6 deletions(-)

src/analyze.cpp+14-1
...@@ -289,13 +289,26 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) {...@@ -289,13 +289,26 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) {
289 }289 }
290 case ZigTypeIdOpaque:290 case ZigTypeIdOpaque:
291 return status < ResolveStatusSizeKnown;291 return status < ResolveStatusSizeKnown;
292 case ZigTypeIdPointer:
293 switch (status) {
294 case ResolveStatusInvalid:
295 zig_unreachable();
296 case ResolveStatusUnstarted:
297 return true;
298 case ResolveStatusZeroBitsKnown:
299 case ResolveStatusAlignmentKnown:
300 case ResolveStatusSizeKnown:
301 return type_entry->abi_size != SIZE_MAX;
302 case ResolveStatusLLVMFwdDecl:
303 case ResolveStatusLLVMFull:
304 return type_entry->llvm_type != nullptr;
305 }
292 case ZigTypeIdMetaType:306 case ZigTypeIdMetaType:
293 case ZigTypeIdVoid:307 case ZigTypeIdVoid:
294 case ZigTypeIdBool:308 case ZigTypeIdBool:
295 case ZigTypeIdUnreachable:309 case ZigTypeIdUnreachable:
296 case ZigTypeIdInt:310 case ZigTypeIdInt:
297 case ZigTypeIdFloat:311 case ZigTypeIdFloat:
298 case ZigTypeIdPointer:
299 case ZigTypeIdArray:312 case ZigTypeIdArray:
300 case ZigTypeIdComptimeFloat:313 case ZigTypeIdComptimeFloat:
301 case ZigTypeIdComptimeInt:314 case ZigTypeIdComptimeInt:
src/ir.cpp+16-5
...@@ -23338,6 +23338,12 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_...@@ -23338,6 +23338,12 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2333823338
23339 IrInstruction *casted_ptr = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on);23339 IrInstruction *casted_ptr = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on);
2334023340
23341 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))
23342 return ira->codegen->invalid_instruction;
23343
23344 if ((err = type_resolve(ira->codegen, src_type, ResolveStatusZeroBitsKnown)))
23345 return ira->codegen->invalid_instruction;
23346
23341 if (type_has_bits(dest_type) && !type_has_bits(src_type)) {23347 if (type_has_bits(dest_type) && !type_has_bits(src_type)) {
23342 ErrorMsg *msg = ir_add_error(ira, source_instr,23348 ErrorMsg *msg = ir_add_error(ira, source_instr,
23343 buf_sprintf("'%s' and '%s' do not have the same in-memory representation",23349 buf_sprintf("'%s' and '%s' do not have the same in-memory representation",
...@@ -25435,6 +25441,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -25435,6 +25441,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
25435static ZigType *ir_resolve_lazy_fn_type(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,25441static ZigType *ir_resolve_lazy_fn_type(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,
25436 LazyValueFnType *lazy_fn_type)25442 LazyValueFnType *lazy_fn_type)
25437{25443{
25444 Error err;
25438 AstNode *proto_node = lazy_fn_type->proto_node;25445 AstNode *proto_node = lazy_fn_type->proto_node;
2543925446
25440 FnTypeId fn_type_id = {0};25447 FnTypeId fn_type_id = {0};
...@@ -25482,11 +25489,15 @@ static ZigType *ir_resolve_lazy_fn_type(CodeGen *codegen, IrExecutable *exec, As...@@ -25482,11 +25489,15 @@ static ZigType *ir_resolve_lazy_fn_type(CodeGen *codegen, IrExecutable *exec, As
25482 case ReqCompTimeNo:25489 case ReqCompTimeNo:
25483 break;25490 break;
25484 }25491 }
25485 if (!type_has_bits(param_type) && !calling_convention_allows_zig_types(fn_type_id.cc)) {25492 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
25486 exec_add_error_node(codegen, exec, source_node,25493 if ((err = type_resolve(codegen, param_type, ResolveStatusZeroBitsKnown)))
25487 buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'",25494 return nullptr;
25488 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));25495 if (!type_has_bits(param_type)) {
25489 return nullptr;25496 exec_add_error_node(codegen, exec, source_node,
25497 buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'",
25498 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));
25499 return nullptr;
25500 }
25490 }25501 }
25491 param_info->type = param_type;25502 param_info->type = param_type;
25492 }25503 }