authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-12-24 11:28:10+01:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-01-02 18:53:20+01:00
log271fc6a2479a1c5f2f914c1c40a848bf1b9d70d8
treec0e748428933f8755639b1cb4addf40d027348f3
parent563d9ebfe597b313b265a5a30296c081fe35d87a

Catch more errors during the type resolution phase

Returning the uninitialized/stale error condition made the compiler turn a blind eye to some problems.

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

src/analyze.cpp+5-4
...@@ -2180,7 +2180,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {...@@ -2180,7 +2180,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
2180 ZigType *field_type = resolve_struct_field_type(g, field);2180 ZigType *field_type = resolve_struct_field_type(g, field);
2181 if (field_type == nullptr) {2181 if (field_type == nullptr) {
2182 struct_type->data.structure.resolve_status = ResolveStatusInvalid;2182 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
2183 return err;2183 return ErrorSemanticAnalyzeFail;
2184 }2184 }
2185 if ((err = type_resolve(g, field->type_entry, ResolveStatusSizeKnown))) {2185 if ((err = type_resolve(g, field->type_entry, ResolveStatusSizeKnown))) {
2186 struct_type->data.structure.resolve_status = ResolveStatusInvalid;2186 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
...@@ -2270,7 +2270,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {...@@ -2270,7 +2270,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
2270 ZigType *field_type = resolve_struct_field_type(g, field);2270 ZigType *field_type = resolve_struct_field_type(g, field);
2271 if (field_type == nullptr) {2271 if (field_type == nullptr) {
2272 struct_type->data.structure.resolve_status = ResolveStatusInvalid;2272 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
2273 return err;2273 return ErrorSemanticAnalyzeFail;
2274 }2274 }
22752275
2276 if ((err = type_resolve(g, field_type, ResolveStatusSizeKnown))) {2276 if ((err = type_resolve(g, field_type, ResolveStatusSizeKnown))) {
...@@ -2340,7 +2340,7 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) {...@@ -2340,7 +2340,7 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) {
2340 &field->align))2340 &field->align))
2341 {2341 {
2342 union_type->data.unionation.resolve_status = ResolveStatusInvalid;2342 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
2343 return err;2343 return ErrorSemanticAnalyzeFail;
2344 }2344 }
2345 add_node_error(g, field->decl_node,2345 add_node_error(g, field->decl_node,
2346 buf_create_from_str("TODO implement field alignment syntax for unions. https://github.com/ziglang/zig/issues/3125"));2346 buf_create_from_str("TODO implement field alignment syntax for unions. https://github.com/ziglang/zig/issues/3125"));
...@@ -2467,6 +2467,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {...@@ -2467,6 +2467,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
2467 union_type->data.unionation.resolve_status = ResolveStatusInvalid;2467 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
2468 return ErrorSemanticAnalyzeFail;2468 return ErrorSemanticAnalyzeFail;
2469 }2469 }
2470
2470 if (is_packed) {2471 if (is_packed) {
2471 if ((err = emit_error_unless_type_allowed_in_packed_union(g, field_type, union_field->decl_node))) {2472 if ((err = emit_error_unless_type_allowed_in_packed_union(g, field_type, union_field->decl_node))) {
2472 union_type->data.unionation.resolve_status = ResolveStatusInvalid;2473 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
...@@ -2925,7 +2926,7 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) {...@@ -2925,7 +2926,7 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) {
2925 &field->align))2926 &field->align))
2926 {2927 {
2927 struct_type->data.structure.resolve_status = ResolveStatusInvalid;2928 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
2928 return err;2929 return ErrorSemanticAnalyzeFail;
2929 }2930 }
2930 } else if (packed) {2931 } else if (packed) {
2931 field->align = 1;2932 field->align = 1;
src/codegen.cpp+9-2
...@@ -290,10 +290,16 @@ static LLVMCallConv get_llvm_cc(CodeGen *g, CallingConvention cc) {...@@ -290,10 +290,16 @@ static LLVMCallConv get_llvm_cc(CodeGen *g, CallingConvention cc) {
290 case CallingConventionFastcall:290 case CallingConventionFastcall:
291 if (g->zig_target->arch == ZigLLVM_x86)291 if (g->zig_target->arch == ZigLLVM_x86)
292 return LLVMX86FastcallCallConv;292 return LLVMX86FastcallCallConv;
293 return LLVMFastCallConv;293 return LLVMCCallConv;
294 case CallingConventionVectorcall:294 case CallingConventionVectorcall:
295 if (g->zig_target->arch == ZigLLVM_x86)295 if (g->zig_target->arch == ZigLLVM_x86)
296 return LLVMX86VectorCallCallConv;296 return LLVMX86VectorCallCallConv;
297 // XXX Enable this when the C API exports this enum member too
298#if 0
299 if (target_is_arm(g->zig_target) &&
300 target_arch_pointer_bit_width(g->zig_target->arch) == 64)
301 return LLVMAARCH64VectorCallCallConv;
302#endif
297 return LLVMCCallConv;303 return LLVMCCallConv;
298 case CallingConventionAsync:304 case CallingConventionAsync:
299 return LLVMFastCallConv;305 return LLVMFastCallConv;
...@@ -310,7 +316,8 @@ static LLVMCallConv get_llvm_cc(CodeGen *g, CallingConvention cc) {...@@ -310,7 +316,8 @@ static LLVMCallConv get_llvm_cc(CodeGen *g, CallingConvention cc) {
310 return LLVMARMAAPCSVFPCallConv;316 return LLVMARMAAPCSVFPCallConv;
311 return LLVMCCallConv;317 return LLVMCCallConv;
312 case CallingConventionInterrupt:318 case CallingConventionInterrupt:
313 if (g->zig_target->arch == ZigLLVM_x86 || g->zig_target->arch == ZigLLVM_x86_64)319 if (g->zig_target->arch == ZigLLVM_x86 ||
320 g->zig_target->arch == ZigLLVM_x86_64)
314 return LLVMX86INTRCallConv;321 return LLVMX86INTRCallConv;
315 if (g->zig_target->arch == ZigLLVM_avr)322 if (g->zig_target->arch == ZigLLVM_avr)
316 return LLVMAVRINTRCallConv;323 return LLVMAVRINTRCallConv;